home *** CD-ROM | disk | FTP | other *** search
/ Sun Solutions 1997 April to September / Sun Solutions CD - APR '97 - SEP '97 (704-3778-12 Rev. H)(Sun Microsystems, Inc.)(1997).iso / products / Apple / Demo / INSTALL.SH < prev    next >
Linux/UNIX/POSIX Shell Script  |  1997-01-24  |  105KB  |  2,570 lines

  1. #!/bin/sh
  2. #------------------------------------------------------------------------------
  3. # Apple Open Systems Software Installer
  4. #
  5. #    @(#)Revision is $Id: mae_installer,v 3.45 1996/10/31 19:16:05 steven Exp $
  6. #------------------------------------------------------------------------------
  7.  
  8. #------------------------------------------------------------------------------
  9. # Copyright 1993-96 Apple Computer, Inc.
  10. # All Rights Reserved.
  11. #
  12. # THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF APPLE COMPUTER, INC.
  13. # The copyright notice above does not evidence any actual or
  14. # intended publication of such source code.
  15. #------------------------------------------------------------------------------
  16.  
  17. #------------------------------------------------------------------------------
  18. # Save argc and arg1 as globals
  19. #------------------------------------------------------------------------------
  20. argc=$#                                 # Number of command line args
  21. argv=${@:-''}                           # Arg list - NULL if not set
  22.  
  23. #------------------------------------------------------------------------------
  24. # Make sure we can read and write the message passing file
  25. #------------------------------------------------------------------------------
  26. msg_file="/tmp/$$.MSG"                        # File used for message passing
  27. /bin/cp /dev/null "$msg_file" 2> /dev/null
  28. if [ ! -w "$msg_file" -o ! -r "$msg_file" ]; then
  29.     AssertErr "Cannot access message passing file [ $msg_file ]"
  30. fi
  31. /bin/rm -f "$msg_file"
  32.  
  33. #------------------------------------------------------------------------------
  34. # Make sure we can write to the report file
  35. #------------------------------------------------------------------------------
  36. report_file="/tmp/installer_report$$" 
  37. /bin/cp /dev/null "$report_file" 2> /dev/null
  38. if [ ! -w "$report_file" ]; then
  39.     Alert "$no_report_msg [ $report_file ]"  
  40.     report_file="/dev/null"
  41. fi
  42.  
  43. #--------------------------------------------------------------------------
  44. # Load terminal specific escape sequences into variables
  45. #--------------------------------------------------------------------------
  46. bld=`tput bold 2> /dev/null`            # Turn BOLD atribute ON 
  47. rev=`tput rev 2> /dev/null`             # Turn REVERSE atribute ON 
  48. off=`tput sgr0 2> /dev/null`            # Turn ALL atributes OFF 
  49. clr_scrn=`tput clear 2>/dev/null`       # Clear screen 
  50.  
  51. #------------------------------------------------------------------------------
  52. # Set umask and PATH (include cwd), and save the default IFS
  53. #------------------------------------------------------------------------------
  54. umask 0022
  55. ## DEBUG ## Make sure this path is still valid for all platforms ## DEBUG ##
  56. PATH=/bin:/usr/bin:/usr/ucb:/etc:/usr/etc:/usr/5bin:.
  57. S_IFS="$IFS"                            # Save a copy of a "good" IFS
  58.  
  59. #------------------------------------------------------------------------------
  60. # Save Location and Name information
  61. #------------------------------------------------------------------------------
  62. start_dir="`/bin/pwd`"                  # Directory where user was at launch
  63. launch_dir="`dirname \"$0\"`"           # Directory where installer lives
  64. if [ "$launch_dir" = '.' ]; then        # Make sure that it is an absolute path
  65.     launch_dir="$start_dir"     
  66. elif [ "`expr \"$launch_dir\"// : '\/.*'`" -eq 0 ]; then
  67.     if [ "$start_dir" = '/' ]; then
  68.         launch_dir="${start_dir}$launch_dir"  
  69.     else
  70.         launch_dir="${start_dir}/$launch_dir"  
  71.     fi
  72. fi
  73. installer="`basename \"$0\"`"           # Name of install script 
  74.  
  75. #------------------------------------------------------------------------------
  76. # Find the correct strings file 
  77. #------------------------------------------------------------------------------
  78. d_catalog_dir="C"                       ## DEFAULT ##
  79. catalog_dir="${LC_ALL:-${LC_MESSAGES:-${LANG:-$d_catalog_dir}}}"
  80.  
  81. #------------------------------------------------------------------------------
  82. ## Add new supported locales here #LOCALIZE# ## DEBUG ##
  83. #------------------------------------------------------------------------------
  84. case $catalog_dir in
  85.     C)       catalog_dir="C" ;;
  86.     euc)     catalog_dir="EUC" ;;
  87.     sjis)    catalog_dir="SJIS" ;;
  88. esac
  89.  
  90. #------------------------------------------------------------------------------
  91. ## Locate Installer message strings
  92. #------------------------------------------------------------------------------
  93.  
  94. if [ -r "${launch_dir}/LOCALE/${catalog_dir}/INSTALL.STR" ]; then
  95.     installer_cat_dir="${launch_dir}/LOCALE/${catalog_dir}"
  96.     . "${installer_cat_dir}/INSTALL.STR"          # Load strings
  97. elif [ -r "${start_dir}/LOCALE/${catalog_dir}/INSTALL.STR" ]; then
  98.     installer_cat_dir="${start_dir}/LOCALE/${catalog_dir}"
  99.     . "${installer_cat_dir}/INSTALL.STR"          # Load strings
  100. else
  101.     echo "
  102.     WARNING:
  103.     Cannot locate message file for '$catalog_dir' locale." >&2
  104.  
  105.     ##
  106.     ## If we were looking for the DEFAULT catalog then just bail here
  107.     ##
  108.     if [ "$catalog_dir" = "C" ]; then
  109.         echo "
  110.     WARNING:
  111.     Cannot locate default message file.
  112.  
  113.     The Installation cannot continue until a valid message file is
  114.     available in '${launch_dir}/LOCALE'.
  115.  
  116.     Try setting your locale using the LC_ALL, LC_MESSAGES, or LANG
  117.     environment variables." >&2
  118.     
  119.         exit 5
  120.     fi
  121.  
  122.     ##
  123.     ## Otherwise look for default locale
  124.     ##
  125.     catalog_dir="$d_catalog_dir"            # Try default
  126.     echo "
  127.     Looking for default message file using '${catalog_dir}' locale." >&2
  128.  
  129.     if [ -r "${launch_dir}/LOCALE/${catalog_dir}/INSTALL.STR" ]; then
  130.         installer_cat_dir="${launch_dir}/LOCALE/${catalog_dir}"
  131.         . "${installer_cat_dir}/INSTALL.STR"      # Load strings
  132.     elif [ -r "${start_dir}/LOCALE/${catalog_dir}/INSTALL.STR" ]; then
  133.         installer_cat_dir="${start_dir}/LOCALE/${catalog_dir}"
  134.         . "${installer_cat_dir}/INSTALL.STR"      # Load strings
  135.     else
  136.         echo "
  137.     WARNING:
  138.     Cannot locate default message file.
  139.  
  140.     The Installation cannot continue until a valid message file is
  141.     available in '${launch_dir}/LOCALE'.
  142.  
  143.     Try setting your locale using the LC_ALL, LC_MESSAGES, or LANG
  144.     environment variables." >&2
  145.  
  146.         exit 5
  147.     fi
  148. fi
  149.  
  150. unset LANG
  151. unset LC_ALL
  152. unset LC_MESSAGES
  153.  
  154.  
  155. #------------------------------------------------------------------------------
  156. # Save tty state 
  157. #------------------------------------------------------------------------------
  158. save_stty="`/bin/stty -g`"                        # Save stty settings
  159. /bin/stty intr "^C"                               # Ensure that we know what sends SIGINT
  160.  
  161. #------------------------------------------------------------------------------
  162. # Traps 
  163. #------------------------------------------------------------------------------
  164. trap 'CleanUpExit 3' 1 2 3 15                     # Clean up on signal
  165.  
  166. #------------------------------------------------------------------------------
  167. # Clear Functions - we don't use absolute path names for these so...
  168. #------------------------------------------------------------------------------
  169. unset -f cd echo exit kill
  170.  
  171.  
  172. ###############################################################################
  173. ## Function definitions begin here                                           ##
  174. ###############################################################################
  175.  
  176. #------------------------------------------------------------------------------
  177. #   Alert - display localized ERROR: message 
  178. #------------------------------------------------------------------------------
  179. Alert()
  180. {
  181.     if [ $# -ne 1 ]; then
  182.         AssertErr "No args passed to Alert function."
  183.     fi
  184.     _alert_msg="$1"
  185.  
  186.     TopScreen "$hit_ret_banner_msg"
  187.     echo 
  188.     echo 
  189.     echo "${bld}    ${error_msg}${off}$_alert_msg" 
  190.     echo $off                                     # Just in case bold is left on
  191.     Report "${error_msg} $_alert_msg"             # Save a copy in the report file
  192.     WaitToContinue;
  193. }
  194.  
  195. #------------------------------------------------------------------------------
  196. #   Report - save message in report file
  197. #------------------------------------------------------------------------------
  198. Report()
  199. {
  200.     if [ "$report_file" = "/dev/null" ]; then
  201.         return                                    # Report NOT!
  202.     fi
  203.     if [ $# -ne 1 ]; then
  204.         AssertErr "No args passed to Report function."
  205.     fi
  206.     _report_msg="$1"
  207.  
  208.     echo '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -' >> "$report_file"
  209.     echo "$_report_msg"                                                          >> "$report_file"
  210. }
  211.  
  212. #------------------------------------------------------------------------------
  213. # AskDir - Prompt for a directory name.  Validate before returning.
  214. #------------------------------------------------------------------------------
  215. AskDir()
  216. {
  217.     if [ $# -ne 4 ]; then
  218.         AssertErr "Incorrect number of args passed to AskDir()."
  219.     fi
  220.  
  221.     _ask_dir_prompt="$1"
  222.     _ask_dir_help="$2"
  223.     _ask_dir_pkg_name="$3"
  224.     _ask_dir_write_req="$4"                       # Either 'W' or NULL
  225.     eval _ask_dir_def_loc="\$d_${_ask_dir_pkg_name}_dir"
  226.     
  227.     while :; do
  228.         TopScreen;                                # Clear screen and display banner
  229.         echo "$_ask_dir_prompt" 
  230.         if [ -z "$_ask_dir_def_loc" ]; then
  231.             Prompt "    [$bld$no_default_msg$off] >>> "
  232.         else
  233.             Prompt "    [$default_equals_msg$bld$_ask_dir_def_loc$off] >>> "
  234.         fi
  235.         read _ask_dir_location
  236.     
  237.         ToLower _ask_dir_location                 # Convert to Lowercase
  238.         case "$_ask_dir_location_lwr" in
  239.             '')                  if [ -z "$_ask_dir_def_loc" ]; then
  240.                                      Alert "$alert_no_default_msg"
  241.                                      continue     # No default, ask again
  242.                                  else 
  243.                                      _ask_dir_location="$_ask_dir_def_loc" # Use default
  244.                                  fi
  245.                                  ;;
  246.             "$help_msg"|\
  247.             "$help_short_msg")   DoHelp "$_ask_dir_help"
  248.                                  continue
  249.                                  ;;
  250.             "$quit_msg"|\
  251.             "$quit_short_msg")   AskQuit "$yes_msg"
  252.                                  continue
  253.                                  ;;
  254.             "$q_bang_msg")       CleanUpExit 0
  255.                                  ;;
  256.         esac
  257.  
  258.         # Run validation script
  259.         "${source_dir}/${_ask_dir_pkg_name}.VAL" "$_ask_dir_location" "$msg_file" destination 2> /dev/null
  260.         _ask_dir_pkg_result=$?
  261.         if [ $_ask_dir_pkg_result -ne 0 ]; then   # Error
  262.             if [ -r "$msg_file" -a -s "$msg_file" ]; then
  263.                 ShowErrMsg
  264.             else
  265.                 Alert "$an_error_msg    (destination)"  # Generic msg
  266.             fi
  267.             return 1
  268.         fi                            
  269.         if BadDir "$_ask_dir_location" "$_ask_dir_pkg_name" "$_ask_dir_write_req"; then
  270.             if [ "$_ask_dir_location" = "$_ask_dir_def_loc" ]; then
  271.                 _ask_dir_def_loc=                 # Default didn't work; reset
  272.                 eval ${_ask_dir_pkg_name}_dir=
  273.                 eval d_${_ask_dir_pkg_name}_dir=
  274.             fi
  275.             return 1                              # Bad dir, return ERROR
  276.         fi
  277.         return 0                                  # Dir ok, return SUCCESS
  278.     done
  279. }
  280.  
  281. #------------------------------------------------------------------------------
  282. # AskInstMode - Sets inst_mode
  283. #------------------------------------------------------------------------------
  284. AskInstMode()
  285. {
  286.     if [ -z "$d_inst_mode" ]; then
  287.         AssertErr "No default installation mode in AskInstmode"
  288.     fi
  289.     
  290.     while :; do
  291.         TopScreen;
  292.         case "$d_inst_mode" in
  293.             EASY)   if [ "$e_pkg_cnt" -ge 1 ]; then
  294.                         _inst_mode_prompt="$easy_msg" 
  295.                     else
  296.                         _inst_mode_prompt="$custom_msg"
  297.                         d_inst_mode=CUSTOM
  298.                     fi
  299.                     ;;
  300.             CUSTOM) _inst_mode_prompt="$custom_msg"
  301.                     ;;
  302.             REMOVE) if [ "$r_pkg_cnt" -ge 1 ]; then
  303.                         _inst_mode_prompt="$remove_msg"
  304.                     else
  305.                         _inst_mode_prompt="$custom_msg"
  306.                         d_inst_mode=CUSTOM
  307.                     fi
  308.                     ;;
  309.             *)      AssertErr "Invalid d_inst_mode in AskInstMode." ;;
  310.         esac
  311.  
  312.         echo "$instmode_prompt_msg" 
  313.         echo
  314.         Prompt "    [default=$bld$_inst_mode_prompt$off] >>> "
  315.         read _inst_mode_selection
  316.         ToLower _inst_mode_selection;
  317.         case "$_inst_mode_selection_lwr" in
  318.             '')                    inst_mode="$d_inst_mode"
  319.                                    return
  320.                                    ;;
  321.             "$easy_short_msg"|\
  322.             "$easy_msg")           if [ "$e_pkg_cnt" -eq 0 ]; then
  323.                                        Alert "$no_easy_packages_msg"
  324.                                        continue
  325.                                    fi
  326.                                    inst_mode="EASY"
  327.                                    d_inst_mode="EASY"
  328.                                    return
  329.                                    ;;
  330.             "$custom_short_msg"|\
  331.             "$custom_msg")         inst_mode="CUSTOM"
  332.                                    d_inst_mode="CUSTOM"
  333.                                    return
  334.                                    ;;
  335.             "$remove_short_msg"|\
  336.             "$remove_msg")         if [ "$r_pkg_cnt" -eq 0 ]; then
  337.                                        Alert "$no_rem_packages_msg"
  338.                                        continue
  339.                                    fi
  340.                                    inst_mode="REMOVE"
  341.                                    d_inst_mode="REMOVE"
  342.                                    return
  343.                                    ;;
  344.             "$quit_msg"|\
  345.             "$quit_short_msg")     AskQuit "$yes_msg"
  346.                                    continue
  347.                                    ;;
  348.             "$q_bang_msg")         CleanUpExit 0
  349.                                    ;;
  350.             "$help_msg"|\
  351.             "$help_short_msg")     DoHelp "$instmode_help_msg"
  352.                                    continue
  353.                                    ;;
  354.             *)                     Alert "$alert_not_valid_msg"
  355.                                    continue 
  356.                                    ;; 
  357.         esac
  358.     done
  359. }
  360.  
  361. #------------------------------------------------------------------------------
  362. #   AskQuit - either quit or continue with the install based on input
  363. #------------------------------------------------------------------------------
  364. AskQuit()
  365. {
  366.     if [ $# -ne 1 ]; then
  367.         AssertErr "Incorrect arg count in AskQuit()."
  368.     fi
  369.     quit_default="$1"
  370.  
  371.     if Interactive; then
  372.         in_quit=TRUE;                   # Prevent recursive calls to AskQuit
  373.         AskYesNo "$ask_quit_msg" "$quit_help_msg" "$quit_default"
  374.         in_quit=FALSE                   # Reset flag
  375.         case "$reply" in
  376.             "$yes_msg") CleanUpExit 0 ;; # Clean up and exit
  377.             "$no_msg")  return 0 ;;     # Continue with installation
  378.             *) AssertErr "Invalid return from AskYesNo() in AskQuit()" ;;
  379.         esac
  380.     else
  381.          CleanUpExit 0                  # Just exit if NON-interactive
  382.     fi
  383. }   
  384.  
  385. #------------------------------------------------------------------------------
  386. # FindSourceDir - Sets source_dir
  387. #------------------------------------------------------------------------------
  388. FindSourceDir()
  389. {
  390.     # Do a Pre-check to try to find the source dir
  391.     if [ ${INSTALL_SRC:-NULL} != NULL ]; then     # Check environment variable 
  392.         if [ -f "${INSTALL_SRC}/${o_s}.TOP" ]; then
  393.             d_source_dir="$INSTALL_SRC"
  394.             return 0                              # Happy, Happy, Joy, Joy
  395.         elif [ -f "$INSTALL_SRC/${o_s}/${o_s}.TOP" ]; then
  396.             d_source_dir="${INSTALL_SRC}/$o_s"
  397.             return 0
  398.         fi
  399.     else                                          # Environment variable not set
  400.         if [ -z "$d_source_dir" ]; then           # Should be set in InitVars
  401.             d_source_dir="/cdrom"
  402.         fi
  403.         for check_point in "$launch_dir" "$d_source_dir" "$start_dir"; do
  404.             if [ -f "${check_point}/${o_s}.TOP" ]; then
  405.                 d_source_dir="$check_point"
  406.                 return 0
  407.             elif [ -f "${check_point}/${o_s}/${o_s}.TOP" ]; then
  408.                 d_source_dir="${check_point}/$o_s"
  409.                 return 0
  410.             fi
  411.         done
  412.     fi
  413.  
  414.     Alert "$not_supported_os_msg"
  415.     CleanUpExit 2
  416. }
  417.  
  418. #------------------------------------------------------------------------------
  419. # FindPackages - Locate and verify the packages to be installed
  420. #------------------------------------------------------------------------------
  421. FindPackages()
  422. {
  423.     source_dir="$d_source_dir"      # Use default (reserved for future use)
  424.     pkg_cnt=0                       # Initialize global array subscript
  425.     e_pkg_cnt=0                     # Initialize global array subscript
  426.     r_pkg_cnt=0                     # Initialize global array subscript
  427.  
  428.     if [ -x "$source_dir" ]; then     # Exit if cd will fail
  429.         cd "$source_dir"
  430.     else
  431.         Alert "$cannot_chdir_to_msg    [ $source_dir ].  $quitting_msg"
  432.         CleanUpExit 2
  433.     fi
  434.  
  435.     echo "$find_pkgs_msg"               # Let them know what we are doing
  436.     #--------------------------------------------------------------------------
  437.     # For each PKG file found, try to locate all of the other required files
  438.     #--------------------------------------------------------------------------
  439.     for _fnd_pkg_pkg in `/bin/ls *.PKG 2> /dev/null`; do
  440.         if [ -z "$_fnd_pkg_pkg" ]; then
  441.             Alert "$is_not_correct_dir_msg"
  442.             CleanUpExit 2                         # No PKG files
  443.         fi
  444.         _fnd_pkg_pkg_name="`expr \"$_fnd_pkg_pkg\" : '\(.*\)\.PKG'`"    # Get package (file) name
  445.  
  446.         #----------------------------------------------------------------------
  447.         # Look for the .STR (strings) file
  448.         #----------------------------------------------------------------------
  449.         if [ ! -r "LOCALE/$catalog_dir/${_fnd_pkg_pkg_name}.STR" ]; then
  450.             continue                              # Get next package
  451.         fi
  452.  
  453.         #----------------------------------------------------------------------
  454.         # Look for the .VAL (validation) file
  455.         #----------------------------------------------------------------------
  456.         if [ ! -x "${_fnd_pkg_pkg_name}.VAL" ]; then
  457.             continue                              # Get next package
  458.         fi
  459.  
  460.         #----------------------------------------------------------------------
  461.         # Run validation (preflight) script
  462.         #----------------------------------------------------------------------
  463.         "${source_dir}/${_fnd_pkg_pkg_name}.VAL" '' "$msg_file" preflight 2> /dev/null
  464.         _fnd_pkg_result=$?
  465.         if [ $_fnd_pkg_result -ne 0 ]; then       # Error
  466.             if [ "$quiet" = TRUE -o $_fnd_pkg_result -eq 2 ]; then
  467.                 continue                          # Do not display message
  468.             fi
  469.             if [ -r "$msg_file" -a -s "$msg_file" ]; then
  470.                 ShowErrMsg
  471.             else
  472.                 Alert "$an_error_msg    (preflight)"  # Generic msg
  473.             fi
  474.             echo "$find_pkgs_msg"                 # Let them know what we are doing
  475.             continue                              # Get next package
  476.         fi                            
  477.  
  478.         cd "$source_dir"                          # Just in case VAL script changed cwd
  479.  
  480.         #----------------------------------------------------------------------
  481.         # Look for the .SIZ (size) file
  482.         #----------------------------------------------------------------------
  483.         if [ ! -r "${_fnd_pkg_pkg_name}.SIZ" ]; then
  484.             continue                              # Get next package
  485.         fi
  486.  
  487.         space_req="`/bin/cat ${_fnd_pkg_pkg_name}.SIZ`"       # Space requirements in KB
  488.  
  489.         #----------------------------------------------------------------------
  490.         # Look for the .INS (installer) file
  491.         #----------------------------------------------------------------------
  492.         if [ ! -x "${_fnd_pkg_pkg_name}.INS" ]; then
  493.             continue                              # Get next package
  494.         fi
  495.  
  496.         #----------------------------------------------------------------------
  497.         # Look for the .NAM (name) file
  498.         #----------------------------------------------------------------------
  499.         if [ ! -r "LOCALE/$catalog_dir/${_fnd_pkg_pkg_name}.NAM" ]; then
  500.             continue                              # Get next package
  501.         fi
  502.  
  503.         #----------------------------------------------------------------------
  504.         # Make a note if package is part of 'Easy Install'
  505.         #----------------------------------------------------------------------
  506.         match_chars=`expr "$_fnd_pkg_pkg_name" : 'E.*'`  # Is an Easy Install package
  507.         if [ "$match_chars" -ne 0 ]; then
  508.             e_pkg_cnt=`expr $e_pkg_cnt + 1`   
  509.             eval e_package_$e_pkg_cnt="$_fnd_pkg_pkg_name" 
  510.         fi
  511.  
  512.         #----------------------------------------------------------------------
  513.         # Make a note if package can be listed under 'Remove' option
  514.         #----------------------------------------------------------------------
  515.         "${source_dir}/${_fnd_pkg_pkg_name}.VAL" '' /dev/null ask_rem 2> /dev/null
  516.  
  517.         if [ $? -eq 0 ]; then
  518.             r_pkg_cnt=`expr $r_pkg_cnt + 1`
  519.             eval r_package_$r_pkg_cnt="$_fnd_pkg_pkg_name"
  520.         fi
  521.  
  522.         #----------------------------------------------------------------------
  523.         # Make a note if package install or remove requires system reboot
  524.         #----------------------------------------------------------------------
  525.         "${source_dir}/${_fnd_pkg_pkg_name}.VAL" '' /dev/null ask_reboot 2> /dev/null
  526.  
  527.         if [ $? -eq 0 ]; then
  528.             eval reboot_${_fnd_pkg_pkg_name}="TRUE" # Requires reboot
  529.         else
  530.             eval reboot_${_fnd_pkg_pkg_name}="FALSE" # Does not require reboot
  531.         fi
  532.  
  533.         #----------------------------------------------------------------------
  534.         # Load all other package information into arrays
  535.         #----------------------------------------------------------------------
  536.         pkg_cnt=`expr $pkg_cnt + 1`               # Increment package count
  537.         eval package_$pkg_cnt="$_fnd_pkg_pkg_name" # Name saved in array of names
  538.         eval ${_fnd_pkg_pkg_name}_size=$space_req # Space requirements
  539.         eval inst_$_fnd_pkg_pkg_name=''           # Initialize Only
  540.     done
  541.  
  542.     #--------------------------------------------------------------------------
  543.     # If no packages are found then we have to exit
  544.     #--------------------------------------------------------------------------
  545.     if [ $pkg_cnt -eq 0 ]; then        
  546.         Alert "$is_not_correct_dir_msg"           # No packages found!
  547.         CleanUpExit 2
  548.     fi
  549.     if [ "$e_pkg_cnt" -eq 0 -a "$inst_mode" = EASY ]; then
  550.         Alert "$no_easy_packages_msg"
  551.         CleanUpExit 0
  552.     fi
  553.     if [ "$r_pkg_cnt" -eq 0 -a "$inst_mode" = REMOVE ]; then
  554.         Alert "$no_rem_packages_msg"
  555.         CleanUpExit 0
  556.     fi
  557. }
  558.  
  559. #------------------------------------------------------------------------------
  560. # AskInstPkgs - Ask user if they want to install each package in turn
  561. #------------------------------------------------------------------------------
  562. AskInstPkgs()
  563. {
  564.     _ask_inst_cnt=1
  565.     while [ $_ask_inst_cnt -le $pkg_cnt ]; do
  566.         default_destination=''                       
  567.         eval _ask_inst_pkg_name="\$package_$_ask_inst_cnt"
  568.  
  569.         #----------------------------------------------------------------------
  570.         # Default is YES for Easy packages and NO for other packages.
  571.         #----------------------------------------------------------------------
  572.         match_chars=`expr "$_ask_inst_pkg_name" : 'E.*'`  # Is an Easy Install package
  573.         if [ "$match_chars" -ne 0 ]; then
  574.             eval _ask_inst_default="\${inst_$_ask_inst_pkg_name:-$yes_msg}" # Easy
  575.         else
  576.             eval _ask_inst_default="\${inst_$_ask_inst_pkg_name:-$no_msg}"  # Custom
  577.         fi
  578.  
  579.         . "$source_dir/LOCALE/$catalog_dir/${_ask_inst_pkg_name}.STR"
  580.     default_destination="${d_dest_dir}/${relative_destination}"
  581.  
  582.         #----------------------------------------------------------------------
  583.         # AskYesNo returns "yes" or "no" in $reply
  584.         #----------------------------------------------------------------------
  585.         AskYesNo "$install_prompt_msg" "$install_help_msg" "$_ask_inst_default"
  586.  
  587.         eval inst_$_ask_inst_pkg_name="$reply" 
  588.         
  589.         if [ "$reply" = "$yes_msg" ]; then
  590.             "${source_dir}/${_ask_inst_pkg_name}.VAL" '' /dev/null ask_dest >/dev/null 2>&1
  591.             ask_dest=$?
  592.             if [ "$ask_dest" -ne 0 ]; then # Dont ask for destination
  593.                 #--------------------------------------------------------------
  594.                 # Validate destination
  595.                 #--------------------------------------------------------------
  596.                 if [ -z "$default_destination" ]; then
  597.                     AssertErr "default_destination not set in AskInstPkgs"
  598.                 fi
  599.                 _dest_dir="`eval echo $default_destination`"
  600.                 eval d_${_ask_inst_pkg_name}_dir="$_dest_dir"
  601.  
  602.                 "${source_dir}/${_ask_inst_pkg_name}.VAL" "`eval echo \\\$d_${_ask_inst_pkg_name}_dir`" "$msg_file" destination 2>> "$report_file"
  603.                 _ask_inst_result=$?
  604.                 if [ $_ask_inst_result -ne 0 ]; then    # Error
  605.                     if [ -r "$msg_file" -a -s "$msg_file" ]; then
  606.                         ShowErrMsg
  607.                     else
  608.                         Alert "$an_error_msg    (destination)"  # Generic msg
  609.                     fi
  610.                     continue
  611.         fi
  612.         if [ "$ask_dest" -ne 2 ] ; then 
  613.           if BadDir "`eval echo \\\$d_${_ask_inst_pkg_name}_dir`" "$_ask_inst_pkg_name" W; then
  614.             continue
  615.           fi
  616.         fi
  617.             else
  618.                 SetTopDir
  619.                 eval d_${_ask_inst_pkg_name}_dir=\${d_${_ask_inst_pkg_name}_dir:-\"$d_dest_dir\"}
  620.                 #--------------------------------------------------------------
  621.                 # The AskDir function will modify the value of <_ask_inst_pkg_name>_dir. 
  622.                 #--------------------------------------------------------------
  623.                 AskDir "$destination_prompt_msg" "$destination_help_msg" "$_ask_inst_pkg_name" W 
  624.                 if [ $? -ne 0 ]; then                 # Bad Dir - go back
  625.                     continue                          # Ask if they want to install
  626.                 fi
  627.                 eval d_dest_dir=\$${_ask_inst_pkg_name}_dir   # For SetTopDir
  628.         if [ "$_ask_inst_pkg_name" = "E1_MAE" ]; then
  629.                     master_d_dest_dir="$d_dest_dir" # Set once and save
  630.         fi
  631.         d_dest_dir=${master_d_dest_dir}
  632.             fi
  633.         fi
  634.         _ask_inst_cnt=`expr $_ask_inst_cnt + 1`
  635.     done
  636.         
  637.     return
  638. }
  639.  
  640. #------------------------------------------------------------------------------
  641. # ListRemPkgs - List all of the packages that the installer knows how to remove
  642. #------------------------------------------------------------------------------
  643. ListRemPkgs()
  644. {
  645.     if [ "$r_pkg_cnt" -eq 0 ]; then
  646.         AssertErr "No removable packages in ListRemPkgs"
  647.     fi
  648.  
  649.     TopScreen "$hit_ret_banner_msg"               # Clear screen and display header
  650.     echo "$can_remove_these_msg"
  651.     _list_rem_cnt=1
  652.     while [ $_list_rem_cnt -le $r_pkg_cnt ]; do
  653.         eval _list_rem_pkg_name="\$r_package_$_list_rem_cnt"
  654.         echo "        `/bin/cat \"$source_dir/LOCALE/$catalog_dir/${_list_rem_pkg_name}.NAM\"`"
  655.         _list_rem_cnt=`expr $_list_rem_cnt + 1`
  656.     done
  657.     echo
  658.     WaitToContinue
  659. }
  660. #------------------------------------------------------------------------------
  661. # AskRemPkgs - Ask user if they want to remove each package in turn
  662. #------------------------------------------------------------------------------
  663. AskRemPkgs()
  664. {
  665.     if [ "$r_pkg_cnt" -eq 0 ]; then
  666.         AssertErr "No removable packages in AskRemPkgs"
  667.     fi
  668.  
  669.     ListRemPkgs     # List all of the packages that the installer knows how to remove
  670.  
  671.     _ask_rem_cnt=1
  672.     while [ $_ask_rem_cnt -le $r_pkg_cnt ]; do
  673.         eval _ask_rem_pkg_name="\$r_package_$_ask_rem_cnt"
  674.         . "$source_dir/LOCALE/$catalog_dir/${_ask_rem_pkg_name}.STR"
  675.     default_destination="${d_dest_dir}/${relative_destination}"
  676.         eval _ask_rem_default="\${rem_$_ask_rem_pkg_name:-$no_msg}" 
  677.         #------------------------------------------------------------------
  678.         # AskYesNo returns "yes" or "no" in $reply
  679.         #------------------------------------------------------------------
  680.         AskYesNo "$remove_prompt_msg" "$remove_help_msg" "$_ask_rem_default"
  681.         eval rem_$_ask_rem_pkg_name="$reply" 
  682.       
  683.         if [ "$reply" = "$yes_msg" ]; then
  684.             "${source_dir}/${_ask_rem_pkg_name}.VAL" '' /dev/null ask_dest >/dev/null 2>&1
  685.             ask_dest=$?
  686.             if [ "$ask_dest" -eq 0 ]; then
  687.                 SetTopDir
  688.                 eval d_${_ask_rem_pkg_name}_dir=\${d_${_ask_rem_pkg_name}_dir:-\"$d_dest_dir\"}
  689.                 #----------------------------------------------------------
  690.                 # The AskDir function will modify the value of <_ask_rem_pkg_name>_dir. 
  691.                 #----------------------------------------------------------
  692.                 AskDir "$where_is_prompt_msg" "$where_is_help_msg" "$_ask_rem_pkg_name" ''
  693.                 if [ $? -ne 0 ]; then
  694.                     continue                  # Ask (again) if they want to remove pkg
  695.                 fi
  696.                 eval d_dest_dir=\$${_ask_rem_pkg_name}_dir   # For SetTopDir
  697.                 master_d_dest_dir="${master_d_dest_dir:-$d_dest_dir}" # Set once and save
  698.             fi
  699.         fi
  700.         _ask_rem_cnt=`expr $_ask_rem_cnt + 1`
  701.     done
  702.         
  703.     return
  704. }
  705.  
  706. #------------------------------------------------------------------------------
  707. # RemCmdLinePkgs - 
  708. #------------------------------------------------------------------------------
  709. RemCmdLinePkgs()
  710. {
  711.     if [ "$r_pkg_cnt" -eq 0 ]; then
  712.         AssertErr "No removable packages in RemCmdLinePkgs"
  713.     fi
  714.     _ask_rem_cnt=1
  715.     while [ $_ask_rem_cnt -le $r_pkg_cnt ]; do
  716.         eval _ask_rem_pkg_name="\$r_package_$_ask_rem_cnt"
  717.         . "$source_dir/LOCALE/$catalog_dir/${_ask_rem_pkg_name}.STR"
  718.     default_destination="${d_dest_dir}/${relative_destination}"
  719.         eval remove_it="\$rem_$_ask_rem_pkg_name"
  720.       
  721.         if [ "$remove_it" = "$yes_msg" ]; then
  722.             "${source_dir}/${_ask_rem_pkg_name}.VAL" '' /dev/null ask_dest >/dev/null 2>&1
  723.             ask_dest=$?
  724.             if [ "$ask_dest" -eq 0 ]; then
  725.                 SetTopDir
  726.                 eval d_${_ask_rem_pkg_name}_dir=\${d_${_ask_rem_pkg_name}_dir:-\"$d_dest_dir\"}
  727.                 #----------------------------------------------------------
  728.                 # The AskDir function will modify the value of <_ask_rem_pkg_name>_dir. 
  729.                 #----------------------------------------------------------
  730.                 AskDir "$where_is_prompt_msg" "$where_is_help_msg" "$_ask_rem_pkg_name" ''
  731.                 if [ $? -ne 0 ]; then
  732.                     continue                  # Ask (again) if they want to remove pkg
  733.                 fi
  734.                 eval d_dest_dir=\$${_ask_rem_pkg_name}_dir   # For SetTopDir
  735.                 master_d_dest_dir="${master_d_dest_dir:-$d_dest_dir}" # Set once and save
  736.             fi
  737.         fi
  738.         _ask_rem_cnt=`expr $_ask_rem_cnt + 1`
  739.     done
  740.     if [ "$quiet" = TRUE ]; then
  741.     interactive=FALSE
  742.     fi
  743.  
  744.     return
  745. }
  746.  
  747. #------------------------------------------------------------------------------
  748. #   AskYesNo - keep asking a yes/no question till user answers yes/no
  749. #   $3 is default, assumes help will be provided by all calling routines
  750. #------------------------------------------------------------------------------
  751. AskYesNo()
  752. {
  753.     if [ $# -ne 3 ]; then
  754.         AssertErr "Incorrect argument count in AskYesNo()."
  755.     fi
  756.     _ask_y_n_prompt="$1"                         # Local $prompt
  757.     _ask_y_n_help="$2"                           # Local $help
  758.     _ask_y_n_default="$3"                        # Local $default (yes/no)
  759.     if [ "$_ask_y_n_default" != "$yes_msg" -a "$_ask_y_n_default" != "$no_msg" ]; then
  760.         AssertErr "Problem with arguments passed to AskYesNo()."
  761.     fi
  762.  
  763.     while :; do
  764.         TopScreen;
  765.         echo "$_ask_y_n_prompt"  
  766.         Prompt "    [$default_equals_msg$bld$_ask_y_n_default$off] >>> "
  767.         read _ask_y_n_answer
  768.         ToLower _ask_y_n_answer                  # Convert to Lowercase
  769.    
  770.         case "$_ask_y_n_answer_lwr" in
  771.         '')                  reply=$_ask_y_n_default    # Use default
  772.                              return 0
  773.                              ;;
  774.         "$yes_msg"|\
  775.         "$yes_short_msg")    reply="$yes_msg"
  776.                              return
  777.                              ;;
  778.         "$no_msg"|\
  779.         "$no_short_msg")     reply="$no_msg"
  780.                              return
  781.                              ;;
  782.         "$help_msg"|\
  783.         "$help_short_msg")   DoHelp "$_ask_y_n_help"
  784.                              continue
  785.                              ;;
  786.         "$quit_msg"|\
  787.         "$quit_short_msg")   if [ "$in_quit" = "TRUE" ]; then
  788.                                  CleanUpExit 0    # Go to exit
  789.                              fi
  790.                               save_ask_y_n_prompt="$_ask_y_n_prompt"
  791.                               save_ask_y_n_help="$_ask_y_n_help"
  792.                               save_ask_y_n_default="$_ask_y_n_default"
  793.                              AskQuit "$yes_msg"   # Quit (or return here)
  794.                               _ask_y_n_prompt="$save_ask_y_n_prompt"
  795.                               _ask_y_n_help="$save_ask_y_n_help"
  796.                               _ask_y_n_default="$save_ask_y_n_default"
  797.                              continue             # Ask again
  798.                              ;;
  799.          "$q_bang_msg")      CleanUpExit 0
  800.                              ;;
  801.         *)   Alert "$alert_not_valid_msg" ;;
  802.        esac
  803.     done
  804. }
  805.  
  806. #------------------------------------------------------------------------------
  807. # AssertErr - Display Alert and exit
  808. #------------------------------------------------------------------------------
  809. AssertErr()
  810. {
  811.     if [ $# -lt 1 ]; then
  812.         _assert_err="No information available"
  813.     else
  814.         _assert_err="$1"
  815.     fi
  816.  
  817.     Alert "$assert_msg
  818.  
  819.     [ $_assert_err ]"
  820.  
  821.     CleanUpExit 1                               
  822. }
  823.  
  824. #------------------------------------------------------------------------------
  825. # BadDir - Check directory accessability, (and writablity) ( return 0 if bad)
  826. #------------------------------------------------------------------------------
  827. BadDir()
  828. {
  829.     # Usage: BadDir <dir_name> <pkg_name>  W | ''
  830.  
  831.     if [ $# -ne 3 -o "$3" != W -a "$3" != '' ]; then
  832.         AssertErr "Problem with argument list in BadDir()." 
  833.     fi
  834.  
  835.     _bad_dir_dir="$1"
  836.     _bad_dir_pkg_name="$2"
  837.     if [ "$3" = W ]; then
  838.         _need_write_access=TRUE
  839.     else
  840.         _need_write_access=FALSE
  841.     fi
  842.     
  843.     echo "$checking_directory_msg"                # This takes a bit of time - warn them
  844.  
  845.     #--------------------------------------------------------------------------
  846.     # Prevent user from getting the shell to do nasty things here.
  847.     #--------------------------------------------------------------------------
  848.     _bad_dir_dir="`echo "$_bad_dir_dir" | cut -d';' -f1`"           # Remove any junk after a ';'
  849.     _bad_dir_dir="`echo "$_bad_dir_dir" | cut -d'|' -f1`"           # Remove any junk after a '|'
  850.  
  851.     #--------------------------------------------------------------------------
  852.     # Use shell to expand path.  Allows for $HOME stuff
  853.     #--------------------------------------------------------------------------
  854.     _bad_dir_dir="`eval echo \"$_bad_dir_dir\"`"  # Expand path
  855.     
  856.     if [ $? -ne 0 -o "`expr \"$_bad_dir_dir\"// : '.*~.*'`" -ne 0 ]; then
  857.         Alert "$badly_formed_path_msg" 
  858.         return 0                                  # Path must contain bad chars
  859.     fi
  860.  
  861.     if [ "`expr \"$_bad_dir_dir\"// : '\/.*'`" -eq 0 ]; then
  862.         _bad_dir_dir="$start_dir/$_bad_dir_dir"   # Prepend path if not absolute
  863.     fi
  864.  
  865.     if [ ! -d "$_bad_dir_dir" ]; then
  866.         if [ "$_need_write_access" = TRUE ]; then # Write access required
  867.             if MakeDir "$_bad_dir_dir"; then      # Try to create dir
  868.                 :                                 # Remember to remove this dir later
  869.             else                                  
  870.                 Alert "$cannot_create_dir_msg    [$_bad_dir_dir]." 
  871.                 return 0                          # Return TRUE (is bad dir)
  872.             fi
  873.         else                                      # We should not create dir
  874.             Alert "$dir_not_exist_msg    [$_bad_dir_dir]."    
  875.             return 0                              # Return TRUE (is bad dir)
  876.         fi
  877.     fi                                            # Dir must exist
  878.  
  879.     chmod u+rwx "$_bad_dir_dir" 2> /dev/null      # Ensure full access to dir
  880.  
  881.     #------------------------------------------------------------------------
  882.     # If destination directory is not accessable then display alert and return
  883.     #------------------------------------------------------------------------
  884.     if [ ! -x "$_bad_dir_dir" ]; then
  885.         Alert "$cannot_chdir_to_msg    [$_bad_dir_dir]"       # Cannot chdir to directory
  886.         return 0                                  # Return TRUE (is bad dir)
  887.     else
  888.         cd "$_bad_dir_dir" 2> /dev/null           
  889.         _bad_dir_dir="`/bin/pwd`"                 # Get REAL path (resolves sym-links, etc.)
  890.     fi
  891.     if [ ! -r "$_bad_dir_dir" ]; then
  892.         Alert "$cannot_read_from_msg    [$_bad_dir_dir]"      # Cannot read from directory
  893.         return 0                                  # Return TRUE (is bad dir)
  894.     fi
  895.  
  896.     #--------------------------------------------------------------------------
  897.     # Must be fully expanded before calling SpaceCheck
  898.     #--------------------------------------------------------------------------
  899.     eval ${_bad_dir_pkg_name}_dir=\"$_bad_dir_dir\"                 
  900.     eval d_${_bad_dir_pkg_name}_dir=\"$_bad_dir_dir\"  
  901.     
  902.     #------------------------------------------------------------------------
  903.     # If two args then test for writability and free space
  904.     #------------------------------------------------------------------------
  905.     if [ "$_need_write_access" = TRUE ]; then     # Write test request
  906.         if [ -w "$_bad_dir_dir" ]; then           # If we can write to the dir
  907.             $mkdir_cmd "$mkdir_opt" "${_bad_dir_dir}/$$" 2> /dev/null  
  908.             if [ -d "${_bad_dir_dir}/$$" ]; then  # Double Check!! (r/o NFS mounts)
  909.                 /bin/rmdir "${_bad_dir_dir}/$$" 2> /dev/null        # Clean up tmp dir
  910.             else                                  # Don't be fooled by CD-ROMs
  911.                 Alert "$cannot_write_to_msg    [$_bad_dir_dir]"   # Cannot write to directory
  912.                 return 0                          # Return TRUE (is bad dir) 
  913.             fi
  914.         else
  915.             Alert "$cannot_write_to_msg    [$_bad_dir_dir]"   # Cannot write to directory
  916.             return 0                              # Return TRUE (is bad dir)
  917.         fi
  918.         #--------------------------------------------------------------------
  919.         # Check for free space on volume
  920.         #--------------------------------------------------------------------
  921.         if SpaceCheck "$_bad_dir_dir" "$_bad_dir_pkg_name"; then
  922.             if [ "${we_made_dir:-FALSE}" = TRUE ]; then    # Only if we made the dir
  923.                 cd "$start_dir"                   # In case we're in the dir to be removed
  924.                 /bin/rmdir "$_bad_dir_dir" 2> /dev/null
  925.             fi
  926.             return 1                              # Return FALSE (not bad dir)
  927.         else
  928.             if [ "${we_made_dir:-FALSE}" = TRUE ]; then    # Only if we made the dir
  929.                 cd "$start_dir"                   # In case we're in the dir to be removed
  930.                 /bin/rmdir "$_bad_dir_dir" 2> /dev/null
  931.             fi
  932.             return 0                              # Return TRUE (is bad dir)
  933.         fi
  934.     fi
  935.  
  936.     return 1                                      # Return FALSE (not bad dir)
  937. }
  938.  
  939. #------------------------------------------------------------------------------
  940. #   CleanUpExit -  Clean up and partially installed files then call exit
  941. #   with the status in arg[1].
  942. #------------------------------------------------------------------------------
  943. CleanUpExit()
  944. {
  945. trap 'echo $done_msg; exit 0' 1 2 3 15            # Just exit if we get another signal
  946.         #---------------------------------------------------#
  947.         #   exit status 0 is normal                         #
  948.         #   exit status 1 is ASSERTION ERROR                #
  949.         #   exit status 2 is I/O ERROR, parameter ERROR     #
  950.         #   exit status 3 is SIGNAL                         #
  951.         #---------------------------------------------------#
  952.  
  953.     if [ $# -ne 1 ]; then
  954.         AssertErr "Incorrect arg count in CleanUpExit()."
  955.     fi
  956.     _exit_status=$1
  957.  
  958.     echo "$off"                                   # Undo any screen effects
  959.     /bin/stty "$save_stty"                        # Reset to original settings
  960.     /bin/rm -f "$msg_file"                        # Remove temp file for this session
  961.  
  962.     if [ "$_exit_status" -eq 3 ]; then
  963.         Report "Terminated by signal"
  964.     fi
  965.  
  966.     #--------------------------------------------------------------------------
  967.     # Tell them about the report file, if one exists
  968.     #--------------------------------------------------------------------------
  969.     if [ "$report_file" != "/dev/null" -a -s "$report_file" -a $_exit_status -ne 99 ]; then
  970.         echo "$read_the_report_msg [ $report_file ]"
  971.         echo; echo
  972.     fi
  973.  
  974.     #--------------------------------------------------------------------------
  975.     # No cleanup required if status 0 
  976.     #--------------------------------------------------------------------------
  977.     if [ $_exit_status -eq 0 ]; then
  978.         exit 
  979.     fi
  980.  
  981.     if [ $_exit_status -ne 99 ]; then 
  982.         #----------------------------------------------------------------------
  983.         # Set a signal handler to protect us and then kill everyone in our proc grp
  984.         # (HP-UX 9.01 does not support killing negative PIDs; can you say BUG!))
  985.         #----------------------------------------------------------------------
  986.         trap 'CleanUpExit 99' 15                  # Run this func again on SIGTERM
  987.         kill -15 0  > /dev/null 2>&1              # Send SIGTERM to init (sent to all in proc grp)
  988.         # kill -15 -$$ > /dev/null 2>&1             # Kill the currently running install script
  989.     fi
  990.  
  991.     #--------------------------------------------------------------------------
  992.     # Otherwise clean up any installed files
  993.     #--------------------------------------------------------------------------
  994.     Prompt "$cleaning_up_msg"                   
  995.  
  996.     #--------------------------------------------------------------------------
  997.     # Make sure those pesky kids are dead
  998.     #--------------------------------------------------------------------------
  999.     wait $! > /dev/null 2>&1
  1000.  
  1001.     if [ "$inst_mode" != REMOVE -a ${_do_inst_status:-0} -eq 99 ]; then
  1002.         "${source_dir}/${_do_inst_pkg_name}.INS" "$_do_inst_destination" "$msg_file" cleanup 2> /dev/null
  1003.         if [ $? -ne 0 ]; then
  1004.             if [ -r "$msg_file" -a -s "$msg_file" ]; then
  1005.                 ShowErrMsg
  1006.             fi
  1007.         fi
  1008.     fi
  1009.     #--------------------------------------------------------------------------
  1010.     # Add any new cleanup code here.     
  1011.     #--------------------------------------------------------------------------
  1012.  
  1013.     echo "$done_msg"               
  1014.     exit $_exit_status
  1015. }
  1016.  
  1017. #------------------------------------------------------------------------------
  1018. # Confirm - Return TRUE (0) to continue; FALSE (1) to make changes
  1019. #------------------------------------------------------------------------------
  1020. Confirm()
  1021. {
  1022.     Interactive || return 0                      # Don't do this if non-interactive
  1023.  
  1024.     if [ "$inst_mode" != EASY -a "$inst_mode" != CUSTOM -a "$inst_mode" != REMOVE ]; then
  1025.          AssertErr "Invalid installation mode in Confirm()."
  1026.     fi
  1027.  
  1028.     #--------------------------------------------------------------------------
  1029.     # Check for No Packages Selected
  1030.     #--------------------------------------------------------------------------
  1031.     _confirm_cnt=1
  1032.     while [ $_confirm_cnt -le $pkg_cnt ]; do
  1033.         eval _confirm_pkg_name="\$package_$_confirm_cnt"
  1034.         if [ "$inst_mode" = REMOVE ]; then
  1035.             eval _confirm_install="\$rem_$_confirm_pkg_name"
  1036.         else
  1037.             eval _confirm_install="\$inst_$_confirm_pkg_name"
  1038.         fi
  1039.         if [ "$_confirm_install" = "$yes_msg" ]; then
  1040.             break                                 # There is at least one package to install
  1041.         fi
  1042.         _confirm_cnt="`expr $_confirm_cnt + 1`"
  1043.     done
  1044.     if [ $_confirm_cnt -gt $pkg_cnt ]; then  
  1045.         if [ "$inst_mode" = REMOVE ]; then
  1046.             Alert "$no_rem_packages_selected_msg"
  1047.         else
  1048.             Alert "$no_inst_packages_selected_msg"
  1049.         fi
  1050.         return 1
  1051.     fi
  1052.         
  1053.     if [ "$inst_mode" = REMOVE ]; then 
  1054.         _confirm_prompt="$confirm_remove_msg"
  1055.     else
  1056.         _confirm_prompt="$confirm_install_msg"
  1057.     fi
  1058.  
  1059.     _confirm_cnt=1
  1060.     _appletalk_package=0
  1061.     _volume_package=0
  1062.     _mae_package=0
  1063.     while [ $_confirm_cnt -le $pkg_cnt ]; do
  1064.         eval _confirm_pkg_name="\$package_$_confirm_cnt"
  1065.         if [ "$inst_mode" = REMOVE ]; then
  1066.             eval _confirm_install="\$rem_$_confirm_pkg_name"
  1067.         else
  1068.             eval _confirm_install="\$inst_$_confirm_pkg_name"
  1069.         fi
  1070.         if [ "$_confirm_install" = "$yes_msg" ]; then
  1071.         if [ "$_confirm_pkg_name" = "E3_VOLD" ] ; then
  1072.                 _volume_package=1
  1073.             fi
  1074.         if [ "$_confirm_pkg_name" = "E2_ATALK" ]; then
  1075.         _appletalk_package=1
  1076.         fi
  1077.         if [ "$_confirm_pkg_name" = "E1_MAE" ]; then
  1078.         _mae_package=1
  1079.         fi
  1080.             . "$source_dir/LOCALE/$catalog_dir/${_confirm_pkg_name}.STR"   # Load package strings
  1081.         default_destination="${d_dest_dir}/${relative_destination}"
  1082.             _confirm_prompt="$_confirm_prompt
  1083.         $package_name_msg"
  1084.         fi
  1085.     _confirm_cnt="`expr $_confirm_cnt + 1`"
  1086.     done
  1087.  
  1088.     Report "$_confirm_prompt"                     # Keep a list in the report file
  1089.     if [ "$inst_mode" = REMOVE ]; then
  1090.         _confirm_prompt="$_confirm_prompt $do_you_want_to_cont_rem_msg"
  1091.         _confirm_help="$confirm_rem_help_msg"
  1092.     else
  1093.         _confirm_prompt="$_confirm_prompt $do_you_want_to_cont_inst_msg"
  1094.         _confirm_help="$confirm_inst_help_msg"
  1095.     if [ "$_appletalk_package" = 0 -a "$_mae_package" = 1 ]; then
  1096.             "${source_dir}/E2_ATALK.INS" "$launch_dir" "$msg_file" version
  1097.         _tmp=$?
  1098.         if [ $_tmp = 0 ]; then
  1099.         _confirm_prompt="$_confirm_prompt$appletalk_not_installed"
  1100.         Report "$appletalk_not_installed"
  1101.         fi
  1102.         if [ $_tmp = 2 ]; then
  1103.         _confirm_prompt="$_confirm_prompt$appletalk_version_mismatch"
  1104.         Report "$appletalk_version_mismatch"
  1105.         fi
  1106.     fi
  1107.     if [ "$o_s" = 'SOLARIS' ] ; then
  1108.                volume_dir="/usr/lib"
  1109.             if [ "$_volume_package" = 0 -a "$_mae_package" = 1 ] ; then
  1110.                if [ -f "$volume_dir/rmmount/action_macfs.so.1" \
  1111.                     -a -f "$volume_dir/fs/macfs/ident_macfs.so.1" ] ; then
  1112.                        cd /tmp
  1113.                        cpio -idm .file_info < "${source_dir}/E3_VOLD.PKG" > /dev/null 2>&1
  1114.                        CheckA="`grep iden* .file_info`"
  1115.                        CheckB="`grep action* .file_info`"
  1116.                        rm -rf .file_info
  1117.                        cd /usr/lib
  1118.                        CheckC="`sum -r fs/macfs/ident_macfs.so.1`"
  1119.                        CheckD="`sum -r rmmount/action_macfs.so.1`"
  1120.                        if [ "$CheckA" = "$CheckC" -a "$CheckB" = "$CheckD" ] ; then
  1121.                             cd "${source_dir}"
  1122.                        else
  1123.                 cd "${source_dir}"
  1124.                             _confirm_prompt="$_confirm_prompt$volume_version_mismatch"
  1125.                             Report "$volume_version_mismatch"
  1126.                        fi
  1127.                else
  1128.                        _confirm_prompt="$_confirm_prompt$no_volume_manager_msg"
  1129.                    Report "$no_volume_manager_msg"    
  1130.                fi
  1131.             fi
  1132.         fi
  1133.     fi
  1134.  
  1135.     AskYesNo "$_confirm_prompt" "$_confirm_help" "$yes_msg"
  1136.     case "$reply" in
  1137.         "$yes_msg") return 0 ;;                   # Proceed
  1138.         "$no_msg")  return 1 ;;                   # Start over
  1139.     esac
  1140. }
  1141.  
  1142. #------------------------------------------------------------------------------
  1143. # DoClear - Clear screen (if supported)
  1144. #------------------------------------------------------------------------------
  1145. DoClear()
  1146. {
  1147.     if [ "$can_clear" = TRUE ]; then
  1148.         Prompt "$clr_scrn"                        # Clear screen
  1149.     else
  1150.         # Incrementing loops in sh are toooo slooooww.
  1151.         echo; echo; echo; echo; echo; echo; echo; echo; 
  1152.         echo; echo; echo; echo; echo; echo; echo; echo; 
  1153.         echo; echo; echo; echo; echo; echo; echo; echo; 
  1154.     fi
  1155. }
  1156.  
  1157. #------------------------------------------------------------------------------
  1158. #   DoHelp - display help message and wait for a RETURN to continue
  1159. #------------------------------------------------------------------------------
  1160. DoHelp()
  1161. {
  1162.     if [ $# -ne 1 ]; then
  1163.         AssertErr "Incorrect arg count in DoHelp()."
  1164.     fi
  1165.     _do_help_msg="$1"
  1166.     
  1167.     DoClear;
  1168.     echo "$rev$help_side_msg$help_title_msg$help_side_msg$off"
  1169.     echo "$_do_help_msg" 
  1170.     echo
  1171.     echo 
  1172.     echo "$help_trailer1_msg"
  1173.     echo "$help_trailer2_msg"
  1174.     echo
  1175.  
  1176.     WaitToContinue;
  1177. }
  1178.  
  1179. #------------------------------------------------------------------------------
  1180. # DoInstall - Installs requested packages 
  1181. #------------------------------------------------------------------------------
  1182. DoInstall()
  1183. {
  1184.     if [ "$pkg_cnt" -le 0 ]; then
  1185.         AssertErr "Bogus pkg_cnt in DoInstall."
  1186.     fi
  1187.  
  1188.     if Interactive; then
  1189.         TopScreen "$press_to_stop_msg"
  1190.     else
  1191.         echo; echo "$press_to_stop_msg"
  1192.         sleep 3                                   # Give them a moment to quit
  1193.     fi
  1194.  
  1195.     _error_occurred=FALSE                         # Initialize global
  1196.     appledir=''                                   # set to NULL
  1197.     _do_inst_cnt=1
  1198.     while [ $_do_inst_cnt -le $pkg_cnt ]; do
  1199.         eval _do_inst_pkg_name="\$package_$_do_inst_cnt"
  1200.         eval _do_inst_install="\$inst_$_do_inst_pkg_name"
  1201.         if [ "$_do_inst_install" = "$yes_msg" ]; then
  1202.             _do_inst_destination="`eval echo \\$\${_do_inst_pkg_name}_dir`"
  1203.             appledir="${appledir:-$_do_inst_destination}"     # Set to first directory used  
  1204.             . "$source_dir/LOCALE/$catalog_dir/${_do_inst_pkg_name}.STR" # Load package strings
  1205.         default_destination="${d_dest_dir}/${relative_destination}"
  1206.  
  1207.             #------------------------------------------------------------------
  1208.             # Run the package install script
  1209.             #------------------------------------------------------------------
  1210.             _do_inst_status=99
  1211.             Report "Installing $package_name_msg in $_do_inst_destination."
  1212.             "${source_dir}/${_do_inst_pkg_name}.INS" "$_do_inst_destination" "$msg_file" install 2>> "$report_file"
  1213.             _do_inst_status=$?
  1214.  
  1215.             if [ $_do_inst_status -ne 0 ]; then   # Error
  1216.                 _error_occurred=TRUE              # Global Flag
  1217.                 if [ -r "$msg_file" -a -s "$msg_file" ]; then
  1218.                     ShowErrMsg
  1219.                 else
  1220.                     Alert "$an_error_msg    (install)"  # A generic message
  1221.                     echo
  1222.                 fi
  1223.                 Report "Cleaning up $package_name_msg in $_do_inst_destination."
  1224.                 "${source_dir}/${_do_inst_pkg_name}.INS" "$_do_inst_destination" "$msg_file" cleanup 2>> "$report_file"
  1225.                 if [ $? -ne 0 ]; then
  1226.                     if [ -r "$msg_file" -a -s "$msg_file" ]; then
  1227.                         ShowErrMsg
  1228.                     else
  1229.                         Alert "$an_error_msg    (cleanup)"  # A generic message
  1230.                         echo
  1231.                     fi
  1232.                 fi
  1233.                 if [ $_do_inst_cnt -lt $pkg_cnt ]; then    # Still more packages
  1234.                     AskQuit "$yes_msg"            # Quit (or return here)
  1235.                 fi
  1236.             else                                  # Package installed without error
  1237.                 _do_inst_status=99
  1238.                 Report "Verifying $package_name_msg in $_do_inst_destination."
  1239.                 "${source_dir}/${_do_inst_pkg_name}.INS" "$_do_inst_destination" "$msg_file" verify 2>> "$report_file"
  1240.                 _do_inst_status=$?
  1241.                 if [ $_do_inst_status -ne 0 ]; then   # Verify failed
  1242.                     _error_occurred=TRUE              # Global Flag
  1243.                     if [ -r "$msg_file" -a -s "$msg_file" ]; then
  1244.                         ShowErrMsg
  1245.                     else
  1246.                         Alert "$an_error_msg    (verify)"  # A generic message
  1247.                         echo
  1248.                     fi
  1249.                     Report "Cleaning up $package_name_msg in $_do_inst_destination."
  1250.                     "${source_dir}/${_do_inst_pkg_name}.INS" "$_do_inst_destination" "$msg_file" cleanup 2>> "$report_file"
  1251.                     if [ $? -ne 0 ]; then         # Remove failed
  1252.                         if [ -r "$msg_file" -a -s "$msg_file" ]; then
  1253.                             ShowErrMsg
  1254.                         else
  1255.                             Alert "$an_error_msg    (cleanup)" # A generic message
  1256.                             echo
  1257.                         fi
  1258.                     fi
  1259.                 else
  1260. # Disabled old alias mechanism. SS
  1261.                     #----------------------------------------------------------
  1262.                     # Put entry in AliasList file  # DEBUG: Ick! MAE Specific!
  1263.                     #----------------------------------------------------------
  1264. #                    if [ -d "${appledir}/lib" -a \
  1265. #                         -w "${appledir}/lib" -a \
  1266. #                         -d "${appledir}/sys/Fonts" ]; then
  1267. #                        "${source_dir}/${_do_inst_pkg_name}.VAL" '' /dev/null mk_alias >/dev/null 2>&1
  1268. #            case "$?" in
  1269. #                0)  echo "nonpersistent|home|$_do_inst_destination" >> "${appledir}/lib/AliasList" 2> /dev/null
  1270. #                $sort_cmd -u -o "${appledir}/lib/AliasList" "${appledir}/lib/AliasList"
  1271. #                ;;
  1272. #                1)  ;;
  1273. #                2)  echo "nonpersistent|extras|$_do_inst_destination" >> "${appledir}/lib/AliasList" 2> /dev/null
  1274. #                $sort_cmd -u -o "${appledir}/lib/AliasList" "${appledir}/lib/AliasList"
  1275. #                ;;
  1276. #                        esac
  1277. #                    fi
  1278.  
  1279.             # Put entries into AliasList file
  1280.             if [ -f "${master_d_dest_dir}/lib/AliasList" -a -w "${master_d_dest_dir}/lib/AliasList" ]; then
  1281.             export _do_inst_destination
  1282.             "${source_dir}/${_do_inst_pkg_name}.VAL" "${master_d_dest_dir}" /dev/null mk_alias > /dev/null 2>&1
  1283.             fi
  1284.                     #--------------------------------------
  1285.                     # Set global reboot flag if required
  1286.                     #--------------------------------------
  1287.                     eval _do_inst_reboot="\$reboot_$_do_inst_pkg_name"
  1288.                     if [ "$_do_inst_reboot" = TRUE ]; then
  1289.                         reboot_required=TRUE
  1290.                     fi
  1291.                 fi  
  1292.             fi
  1293.         fi
  1294.         _do_inst_cnt=`expr $_do_inst_cnt + 1`
  1295.     done
  1296.         
  1297.     return
  1298. }
  1299.  
  1300. #------------------------------------------------------------------------------
  1301. # DoRemove - Removes requested packages 
  1302. #------------------------------------------------------------------------------
  1303. DoRemove()
  1304. {
  1305.     if [ "$r_pkg_cnt" -le 0 ]; then
  1306.         AssertErr "No removable packages in DoRemove"
  1307.     fi
  1308.  
  1309.     if Interactive; then
  1310.         TopScreen "$press_to_stop_rmv_msg"
  1311.     else
  1312.         echo; echo "$press_to_stop_rmv_msg"
  1313.         sleep 3                                   # Give them a moment to quit
  1314.     fi
  1315.  
  1316.     _error_occurred=FALSE                         # Initialize global
  1317.     _do_rem_cnt=1
  1318.     while [ $_do_rem_cnt -le $r_pkg_cnt ]; do
  1319.         eval _do_rem_pkg_name="\$r_package_$_do_rem_cnt"
  1320.         eval _do_rem_remove="\$rem_$_do_rem_pkg_name"
  1321.         if [ "$_do_rem_remove" = "$yes_msg" ]; then
  1322.             _do_rem_destination="`eval echo \\$\${_do_rem_pkg_name}_dir`"
  1323.             . "$source_dir/LOCALE/$catalog_dir/${_do_rem_pkg_name}.STR" # Load package strings
  1324.         default_destination="${d_dest_dir}/${relative_destination}"
  1325.         if [ -z "$_do_rem_destination" ]; then
  1326.         _do_rem_destination="$default_destination"
  1327.         fi
  1328.  
  1329.             #------------------------------------------------------------------
  1330.             # Run the package remove script 
  1331.             #------------------------------------------------------------------
  1332.             Report "Removing $package_name_msg from $_do_rem_destination."
  1333.             "${source_dir}/${_do_rem_pkg_name}.INS" "$_do_rem_destination" "$msg_file" remove 2>> "$report_file"
  1334.             if [ $? -ne 0 ]; then
  1335.                 if [ -r "$msg_file" -a -s "$msg_file" ]; then
  1336.                     ShowErrMsg
  1337.                 else
  1338.                     Alert "$an_error_msg    (remove)"  # A generic message
  1339.                     echo
  1340.                 fi
  1341.                 _error_occurred=TRUE
  1342.             fi
  1343.             #--------------------------------------
  1344.             # Set global reboot flag if required
  1345.             #--------------------------------------
  1346.             eval _do_rem_reboot="\$reboot_$_do_rem_pkg_name"
  1347.             if [ "$_do_rem_reboot" = TRUE ]; then
  1348.                 reboot_required=TRUE
  1349.             fi
  1350.         fi
  1351.         _do_rem_cnt=`expr $_do_rem_cnt + 1`
  1352.     done
  1353.         
  1354.     return
  1355. }
  1356.  
  1357. #------------------------------------------------------------------------------
  1358. # Epilogue - Any last requests?
  1359. #------------------------------------------------------------------------------
  1360. Epilogue()
  1361. {
  1362.     if [ "${_error_occurred:-FALSE}" = TRUE ]; then
  1363.         if [ "$inst_mode" = REMOVE ]; then
  1364.             echo "$removal_failed_msg"
  1365.             Report "$removal_failed_msg"
  1366.         else
  1367.             echo "$installation_failed_msg"
  1368.             Report "$installation_failed_msg"
  1369.         fi
  1370.         _exit_code=2
  1371.     else
  1372.     if [ -n "$_no_operation" ]; then
  1373.         echo "$no_operation_msg"
  1374.         Report "$no_operation_msg"
  1375.             _exit_code=1
  1376.     else
  1377.         if [ "$inst_mode" = REMOVE ]; then
  1378.             echo "$remove_complete_msg" 
  1379.                 Report "$remove_complete_msg" 
  1380.             else
  1381.                 echo "$install_complete_msg" 
  1382.                 Report "$install_complete_msg" 
  1383.             fi
  1384.             _exit_code=0 
  1385.         fi
  1386.     fi
  1387.     WaitToContinue
  1388.  
  1389.     # We should check to see if they are logged in as root. 
  1390.     # For now we will assume that packages that require reboot
  1391.     # will also require root login. So it will be handled in
  1392.     # the .VAL script
  1393.     if [ "$reboot_forced" = TRUE ]; then
  1394.     DoClear;
  1395.         AskYesNo "$read_report_prompt_msg" "$read_report_help_msg" "$no_msg"
  1396.         if [ "$reply" = "$yes_msg" ] ; then
  1397.                 more -c "$report_file"
  1398.             WaitToContinue
  1399.         fi
  1400.         Reboot
  1401.     fi
  1402.     if [ "$reboot_required" = TRUE ]; then
  1403.         if [ "$interactive" = TRUE ]; then
  1404.          AskYesNo "$read_report_prompt_msg" "$read_report_help_msg" "$no_msg"
  1405.             if [ "$reply" = "$yes_msg" ] ; then
  1406.                    more -c "$report_file"
  1407.            WaitToContinue
  1408.             fi
  1409.             DoClear;
  1410.             AskYesNo "$reboot_prompt_msg" "$reboot_help_msg" "$no_msg"
  1411.             if [ "$reply" = "$yes_msg" ]; then
  1412.                 Reboot
  1413.             fi
  1414.         else
  1415.             echo "$you_must_reboot_msg"
  1416.             Report "$you_must_reboot_msg"
  1417.         fi
  1418.     fi
  1419.     CleanUpExit $_exit_code
  1420. }
  1421.  
  1422. #------------------------------------------------------------------------------
  1423. # Reboot - Reboot system with default grace period
  1424. #------------------------------------------------------------------------------
  1425. Reboot()
  1426. {
  1427.     cd / 
  1428.  
  1429.     case "$o_s" in
  1430.         HPUX)    reboot
  1431.                  ;;
  1432.         HPUX9)     reboot
  1433.          ;;
  1434.         SOLARIS) reboot
  1435.                  ;;
  1436.         *)       AssertErr "Unsupported O/S in Reboot()"
  1437.                  ;;
  1438.     esac
  1439. }
  1440.  
  1441. #------------------------------------------------------------------------------
  1442. # GetOS - Determine system type and OS
  1443. #------------------------------------------------------------------------------
  1444. GetOS()
  1445. {
  1446.     case "`/bin/uname -s`" in
  1447.          A/UX*)  o_s='AUX'     ;;                 # Apple
  1448.           AIX*)  o_s='unknown' ;;                 # IBM
  1449.         SunOS*)  o_s='SUN'     ;;                 # Sun
  1450.         HP-UX*)  o_s='HPUX'    ;;                 # HP
  1451.              *)  o_s='unknown' ;;                 # unknown
  1452.     esac
  1453.     
  1454.     #--------------------------------------------------------------------------
  1455.     # Additional code to determine O_S version and release
  1456.     #--------------------------------------------------------------------------
  1457.     case $o_s in
  1458.         SUN)     case "`/bin/uname -r`" in
  1459.                  4*) o_s='unknown' ;;             # SunOS 
  1460.                  5*) o_s='SOLARIS' ;;             # Solaris 2.x
  1461.                   *) o_s='unknown' ;;             # unknown
  1462.                  esac
  1463.                  ;;
  1464.     HPUX)      case "`/bin/uname -r | cut -c 3,4,5,6`" in
  1465.              09.0) o_s='HPUX9'   ;;           # for 9 specific installation
  1466.          10.0) o_s='unknown' ;;          # don't support 10.01
  1467.          10.*) o_s='HPUX' ;;
  1468.          *)    o_s='unknown' ;;
  1469.                esac
  1470.                ;;
  1471.     esac
  1472.     
  1473.     if [ "$o_s" = unknown ]; then
  1474.         Alert "[`/bin/uname -sr`]  $not_supported_os_msg." 
  1475.         CleanUpExit 2
  1476.     fi
  1477. }
  1478.  
  1479. #------------------------------------------------------------------------------
  1480. # GetOpts - Get command line options
  1481. #------------------------------------------------------------------------------
  1482. GetOpts()
  1483. {
  1484.     _cnt=1
  1485.     _cnt2=1
  1486.     _match_args=0
  1487.     _pkg_name=""
  1488.     _tmp_string=""
  1489.     _packages_selected=FALSE
  1490.     cmd_line_pkg_cnt=0 ; export cmd_line_pkg_cnt
  1491.     cmd_line_dest=""
  1492.     reboot_required=FALSE
  1493.     reboot_forced=FALSE
  1494.  
  1495.     if [ "$argc" -eq 0 ]; then
  1496.         return
  1497.     fi
  1498.  
  1499.     set -- $argv PED                           # Set positional parameters; end with PED
  1500.     while :; do
  1501.         case "$1" in
  1502.            PED)  break ## return
  1503.                  ;;
  1504.             -q)  quiet=TRUE
  1505.                  shift
  1506.                  ;;
  1507.             -e)  if [ -z "$inst_mode" ]; then
  1508.                      inst_mode=EASY
  1509.                      shift
  1510.                  else
  1511.                      echo; echo "$usage_msg"
  1512.                      CleanUpExit 0
  1513.                  fi
  1514.                  ;;
  1515.             -c)  if [ -z "$inst_mode" ]; then
  1516.                      inst_mode=CUSTOM
  1517.                      shift
  1518.                      while :; do
  1519.                          case "$1" in
  1520.                        PED)  break           # No more package names
  1521.                              ;;
  1522.                          -*) break           # No more package names
  1523.                              ;;
  1524.                          *)  cmd_line_pkg_cnt=`expr $cmd_line_pkg_cnt + 1`
  1525.                              eval cmd_line_pkg_${cmd_line_pkg_cnt}="$1"
  1526.                  eval export cmd_line_pkg_${cmd_line_pkg_cnt}
  1527.                              shift
  1528.                              ;;
  1529.                          esac
  1530.                      done
  1531.  
  1532.                  else
  1533.                      echo; echo "$usage_msg"
  1534.                      CleanUpExit 0
  1535.                  fi
  1536.                  ;;
  1537.             -r)  if [ -z "$inst_mode" ]; then
  1538.                      inst_mode=REMOVE
  1539.                      shift
  1540.                      while :; do
  1541.                          case "$1" in
  1542.                        PED)  break           # No more package names
  1543.                              ;;
  1544.                          -*) break           # No more package names
  1545.                              ;;
  1546.                          *)  cmd_line_pkg_cnt=`expr $cmd_line_pkg_cnt + 1`
  1547.                              eval cmd_line_pkg_${cmd_line_pkg_cnt}="$1"
  1548.                              shift
  1549.                              ;;
  1550.                          esac
  1551.                      done
  1552.  
  1553.                  else
  1554.                      echo; echo "$usage_msg"
  1555.                      CleanUpExit 0
  1556.                  fi
  1557.                  ;;
  1558.             -d)  ## Set destination
  1559.                  shift
  1560.                  if [ "$1" = PED ]; then
  1561.                      echo; echo "$usage_msg"
  1562.                      CleanUpExit 0
  1563.                  else
  1564.                      cmd_line_dest="$1"
  1565.                      d_dest_dir="$1"     ## Default destination
  1566.                      shift
  1567.                  fi
  1568.                  ;;
  1569.              -R) ## Force Reboot
  1570.                  shift
  1571.                  reboot_forced=TRUE
  1572.                  ;;
  1573.              *)  echo; echo "$usage_msg"
  1574.                  CleanUpExit 0
  1575.                  ;;
  1576.         esac
  1577.     done
  1578.  
  1579.     ##
  1580.     ## Sanity check to make sure args are used in valid combinations
  1581.     ##
  1582.  
  1583.     FindPackages               # Look for valid packages
  1584.  
  1585.     if [ "$inst_mode" = CUSTOM ]; then
  1586.         if [ "$cmd_line_pkg_cnt" -eq 0 ]; then
  1587.             continue  ## No packages specified
  1588.         fi
  1589.    
  1590.         ## Do the requested packages exist?
  1591.         _cnt=1; _bad_pkg_cnt=0;
  1592.         while [ "$_cnt" -le "$cmd_line_pkg_cnt" ]; do
  1593.             eval _tmp_string="\$cmd_line_pkg_$_cnt"
  1594.             _found_flag=0
  1595.             _cnt2=1
  1596.             while [ "$_cnt2" -le "$pkg_cnt" ]; do
  1597.                 eval _pkg_name="\$package_$_cnt2"
  1598.                 if [ "$_pkg_name" = "$_tmp_string" ]; then
  1599.                     eval inst_${_pkg_name}="$yes_msg"
  1600.                     _match_args=`expr $_match_args + 1`
  1601.                     _found_flag=1
  1602.                     break
  1603.                 fi
  1604.                 _cnt2=`expr $_cnt2 + 1`
  1605.             done
  1606.  
  1607.             ## Record which package is bad. SS
  1608.             if [ $_found_flag -eq 0 ]; then
  1609.                 _bad_pkg_cnt=`expr $_bad_pkg_cnt + 1`
  1610.                 eval _bad_pkg_${_bad_pkg_cnt}="$_tmp_string"
  1611.             fi
  1612.                               
  1613.             _cnt=`expr $_cnt + 1`
  1614.         done
  1615.         if [ "$_match_args" -ne "$cmd_line_pkg_cnt" ]; then
  1616.             echo "$invalid_pkg_msg"
  1617.             _cnt=1             # Re-initialize
  1618.             while [ "$_cnt" -le "$_bad_pkg_cnt" ]; do
  1619.                 eval _bad_pkg_name="\$_bad_pkg_$_cnt"
  1620.                 echo "        $_bad_pkg_name"
  1621.                 _cnt=`expr $_cnt + 1`
  1622.             done
  1623.             echo ""
  1624.             echo "$choose_from_msg"
  1625.             _cnt=1             # Re-initialize
  1626.             while [ "$_cnt" -le "$pkg_cnt" ]; do
  1627.                 eval _pkg_name="\$package_$_cnt"
  1628.                 echo "        $_pkg_name"
  1629.                 _cnt=`expr $_cnt + 1`
  1630.             done
  1631.             CleanUpExit 0
  1632.         else
  1633.             _packages_selected=TRUE
  1634.         fi
  1635.     fi
  1636.  
  1637.     if [ "$inst_mode" = REMOVE ]; then
  1638.         if [ "$cmd_line_pkg_cnt" -eq 0 ]; then
  1639.             continue       ## No packages specified
  1640.         fi
  1641.    
  1642.         ## Do the requested packages exist?
  1643.         ## And are they removable?
  1644.         _cnt=1; _cnt2=1;
  1645.         while [ "$_cnt" -le "$cmd_line_pkg_cnt" ]; do
  1646.             eval _tmp_string="\$cmd_line_pkg_$_cnt"
  1647.             while [ "$_cnt2" -le "$r_pkg_cnt" ]; do
  1648.                 eval _pkg_name="\$r_package_$_cnt2"
  1649.                 if [ "$_pkg_name" = "$_tmp_string" ]; then
  1650.                     eval rem_${_pkg_name}="$yes_msg"
  1651.                     _match_args=`expr $_match_args + 1`
  1652.                     break
  1653.                 fi
  1654.                 _cnt2=`expr $_cnt2 + 1`
  1655.             done
  1656.               
  1657.             _cnt=`expr $_cnt + 1`
  1658.         done
  1659.         if [ "$_match_args" -ne "$cmd_line_pkg_cnt" ]; then
  1660.             echo "$invalid_pkg_msg \"$_tmp_string\"."
  1661.             echo "$choose_from_msg"
  1662.             _cnt=1             # Re-initialize
  1663.             while [ "$_cnt" -le "$pkg_cnt" ]; do
  1664.                 eval _pkg_name="\$r_package_$_cnt"
  1665.                 echo "        $_pkg_name"
  1666.                 _cnt=`expr $_cnt + 1`
  1667.             done
  1668.             CleanUpExit 0
  1669.         else
  1670.             _packages_selected=TRUE
  1671.         fi
  1672.     fi
  1673. }
  1674.  
  1675. #------------------------------------------------------------------------------
  1676. # InitVars - O/S specific commands loaded into variables
  1677. #------------------------------------------------------------------------------
  1678. InitVars()
  1679. {
  1680.     inst_mode=''
  1681.     quiet=FALSE
  1682.     interactive=TRUE
  1683.  
  1684.     d_inst_mode="EASY" 
  1685.     d_source_dir='/cdrom'
  1686.     d_dest_dir='/opt/apple'                    
  1687.     master_d_dest_dir=''
  1688.  
  1689.     df_cmd='/bin/df'                              
  1690.     format_cmd='/bin/fmt'                         
  1691.     mkdir_cmd='/bin/mkdir'                      
  1692.     mkdir_opt='-p'                      
  1693.     sort_cmd='/bin/sort'                      
  1694.     tput_cmd='/bin/tput'                      
  1695.     if `echo -n XXXX | /bin/grep n > /dev/null 2>&1`; then
  1696.         bsd_echo=FALSE
  1697.     else
  1698.         bsd_echo=TRUE
  1699.     fi
  1700.  
  1701.     case "$o_s" in
  1702.           AIX)    df_arg='-I'                       
  1703.                   ;;
  1704.         SUN_OS)   df_arg=''                       
  1705.                   d_dest_dir='/opt/apple'            
  1706.                   ;;
  1707.         SOLARIS)  df_arg='-k'                       
  1708.                   d_dest_dir='/opt/apple'            
  1709.                   ;;
  1710.          HPUX)    format_cmd='/bin/adjust'         
  1711.                   df_cmd='/usr/bin/bdf'             
  1712.                   df_arg=''                         
  1713.                   tput_cmd='/usr/bin/tput'          
  1714.                   ;;
  1715.          HPUX9)   format_cmd='/bin/adjust'         
  1716.                   df_cmd='/usr/bin/bdf'             
  1717.                   df_arg=''                         
  1718.                   tput_cmd='/usr/bin/tput'          
  1719.                   ;;
  1720.           AUX)    df_arg='-B'                       
  1721.                   tput_cmd='/usr/bin/tput'          
  1722.                   format_cmd='/usr/ucb/fmt'
  1723.                   mkdir_opt=''                      
  1724.                   ;;
  1725.            *)     AssertErr "Unknown O_S type in InitVars()."
  1726.                   ;;
  1727.     esac
  1728.  
  1729.  
  1730.     #--------------------------------------------------------------------------
  1731.     # Test to determine whether we are dumb terminal or smart.
  1732.     #--------------------------------------------------------------------------
  1733.     $tput_cmd clear > /tmp/tput.test$$ 2> /dev/null
  1734.     if [ -s /tmp/tput.test$$ ]; then
  1735.         can_clear=TRUE
  1736.     else
  1737.         can_clear=FALSE
  1738.     fi
  1739.     /bin/rm -f /tmp/tput.test$$
  1740. }
  1741.  
  1742. #------------------------------------------------------------------------------
  1743. # Interactive - Return TRUE (0) if interactive=TRUE
  1744. #------------------------------------------------------------------------------
  1745. Interactive()
  1746. {
  1747.     if [ "$interactive" = TRUE ]; then
  1748.          return 0                                 # We ARE interactive
  1749.     else
  1750.         return 1                                  # We are NOT interactive
  1751.     fi
  1752. }
  1753.  
  1754. #--------------------------------------------------------------------------
  1755. # ListPackages - Let the user know what packages are available
  1756. #--------------------------------------------------------------------------
  1757. ListPackages()
  1758. {
  1759.     TopScreen "$hit_ret_banner_msg"               # Clear screen and display header
  1760.     echo "$here_are_the_pkgs_msg"
  1761.     #----------------------
  1762.     # Easy Only Packages
  1763.     #----------------------
  1764.     if [ "$e_pkg_cnt" -ge 1 ]; then
  1765.         echo "$here_are_the_e_pkgs_msg"
  1766.          _list_pkgs_cnt=1
  1767.         while [ $_list_pkgs_cnt -le $e_pkg_cnt ]; do
  1768.             eval _list_pkgs_pkg_name="\$e_package_$_list_pkgs_cnt"
  1769.             eval _list_pkgs_size="\$${_list_pkgs_pkg_name}_size"
  1770.             # Convert size to number of megabytes or kilobytes
  1771.         if [ "$_list_pkgs_size" -le 1000 ]; then
  1772.             _list_pkgs_size="$_list_pkgs_size"KB
  1773.         else
  1774.                 _list_pkgs_size="`expr $_list_pkgs_size / 1024`"
  1775.                 #------------------------------------------------------------------
  1776.                 # Add 1 to inflate the number slightly (almost the same as rounding up)
  1777.                 #------------------------------------------------------------------
  1778.                 _list_pkgs_size="`expr $_list_pkgs_size + 1`"
  1779.           _list_pkgs_size="$_list_pkgs_size"MB
  1780.         fi
  1781.  
  1782.     
  1783.             echo "        ${_list_pkgs_size}    `/bin/cat \"$source_dir/LOCALE/$catalog_dir/${_list_pkgs_pkg_name}.NAM\"`"
  1784.     
  1785.         _list_pkgs_cnt="`expr $_list_pkgs_cnt + 1`"
  1786.         done
  1787.     fi
  1788.     #--------------------------------------------------------------------------
  1789.     # Other Packages
  1790.     #--------------------------------------------------------------------------
  1791.     if [ "$pkg_cnt" -ge 1 -a "$pkg_cnt" -gt "$e_pkg_cnt" ]; then
  1792.         if [ "$e_pkg_cnt" -ge 1 ]; then
  1793.             echo "$here_are_the_c_pkgs_msg1"
  1794.         else
  1795.             echo "$here_are_the_c_pkgs_msg2"
  1796.         fi
  1797.         _list_pkgs_cnt=1
  1798.         while [ $_list_pkgs_cnt -le $pkg_cnt ]; do
  1799.             eval _list_pkgs_pkg_name="\$package_$_list_pkgs_cnt"
  1800.             match_chars=`expr "$_list_pkgs_pkg_name" : 'E.*'`  # Is an Easy Install package
  1801.             if [ "$match_chars" -ne 0 ]; then
  1802.                 _list_pkgs_cnt="`expr $_list_pkgs_cnt + 1`"
  1803.                 continue                          # Has already been displayed
  1804.             fi
  1805.             eval _list_pkgs_size="\$${_list_pkgs_pkg_name}_size"
  1806.             #------------------------------------------------------------------
  1807.             # Use 1000 (instead of 1024) to inflate the number slightly
  1808.             #------------------------------------------------------------------
  1809.         if [ "$_list_pkgs_size" -le 1000 ]; then
  1810.             _list_pkgs_size="$_list_pkgs_size"KB
  1811.         else
  1812.                 _list_pkgs_size="`expr $_list_pkgs_size / 1000`"
  1813.           _list_pkgs_size="$_list_pkgs_size"MB
  1814.         fi
  1815.  
  1816.             . "$source_dir/LOCALE/$catalog_dir/${_list_pkgs_pkg_name}.STR"   # Load package strings
  1817.         default_destination="${d_dest_dir}/${relative_destination}"
  1818.             echo "        ${_list_pkgs_size}    $package_name_msg"
  1819.     
  1820.         _list_pkgs_cnt="`expr $_list_pkgs_cnt + 1`"
  1821.         done
  1822.     else
  1823.         echo "$here_are_the_c_pkgs_msg0"
  1824.     fi
  1825.     echo
  1826.     WaitToContinue
  1827. }
  1828.  
  1829. #--------------------------------------------------------------------------
  1830. # LoadMountList - load (global) array with mount points and free space
  1831. #--------------------------------------------------------------------------
  1832. LoadMountList()
  1833. {
  1834.     IFS='
  1835. '
  1836.     _ld_mnt_cnt=1
  1837.     _skipped_header=''
  1838.     for _mnt_point in `$df_cmd $df_arg 2> /dev/null`; do
  1839.         if [ -z "$_skipped_header" ]; then
  1840.             _skipped_header="TRUE"
  1841.             continue                              # Skip the header
  1842.         fi
  1843.         set -- `echo X$_mnt_point | awk '{ print($4); print($6) }'`  # Prepend an X for df() bug
  1844.         if [ "${1:-NULL}" = NULL -o "${2:-NULL}" = NULL ]; then
  1845.             continue                              # Must be a bad mount - ignore
  1846.         fi
  1847.         eval free_space_$_ld_mnt_cnt="$1"
  1848.         if [ -d "$2" -a -x "$2" ]; then           # If dir exists and is searchable
  1849.             cd "$2"                               # We're pretty darn sure that the dir exists
  1850.             _tmp_dir="`/bin/pwd 2> /dev/null`"    # Get "real" path (resolve sym-links)
  1851.             if [ $? -ne 0 ]; then
  1852.                 _tmp_dir="$2"                     # Use whatever df() gave us
  1853.             fi
  1854.         else
  1855.             _tmp_dir="$2"                         # Use whatever df() gave us
  1856.         fi
  1857.         eval mnt_point_$_ld_mnt_cnt="$_tmp_dir"
  1858.  
  1859.         _ld_mnt_cnt=`expr $_ld_mnt_cnt + 1`
  1860.     done
  1861.  
  1862.     MAX_MNTS=`expr $_ld_mnt_cnt - 1`              # Global
  1863.     IFS="$S_IFS"
  1864. }
  1865.  
  1866. #------------------------------------------------------------------------------
  1867. # MakeDir - Make directory(s) from supplied path - always absolute path
  1868. #------------------------------------------------------------------------------
  1869. MakeDir()
  1870. {
  1871.     if [ $# -ne 1 ]; then
  1872.         AssertErr "Incorrect arg count in MakeDir()."
  1873.     fi
  1874.     _mk_dir_target="$1"
  1875.     we_made_dir=FALSE                             # Global Flag
  1876.  
  1877.     if [ -d "$_mk_dir_target" ]; then             # Already exists
  1878.         return 0              
  1879.     fi
  1880.  
  1881.     if [ -f "$_mk_dir_target" ]; then             # File with same name exists
  1882.         Alert "$file_not_dir_msg"
  1883.         return 1                                  # Error
  1884.     fi
  1885.  
  1886.     $mkdir_cmd "$mkdir_opt" "$_mk_dir_target" > /dev/null 2>&1
  1887.     if [ ! -d "$_mk_dir_target" ]; then           # Could not make directory
  1888.         return 1                                  # Return Error
  1889.     fi
  1890.  
  1891.     we_made_dir=TRUE                              # Global Flag
  1892.     return 0                                      # Return Success
  1893. }
  1894.  
  1895. #------------------------------------------------------------------------------
  1896. # Prompt - Display prompt - suppress CR/LF 
  1897. #------------------------------------------------------------------------------
  1898. Prompt()
  1899. {
  1900.     if [ $# -ne 1 ]; then
  1901.         AssertErr "Incorrect arg count in Prompt()."
  1902.     fi
  1903.  
  1904.     if [ "$bsd_echo" = TRUE ]; then
  1905.         echo -n "$1"
  1906.     else
  1907.         echo "$1\c"
  1908.     fi
  1909. }
  1910.  
  1911. #------------------------------------------------------------------------------
  1912. # RemoveDir - Remove directory(s) from supplied path, if empty
  1913. #------------------------------------------------------------------------------
  1914. RemoveDir()
  1915. {
  1916.     if [ $# -ne 1 ]; then
  1917.         AssertErr "Incorrect arg count in RemoveDir()."
  1918.     fi
  1919.  
  1920.     _rem_dir_dir="$1"
  1921.     cd "$start_dir"                               # In case we're in the dir to be removed
  1922.     
  1923.     until [ -z "$_rem_dir_dir" ]; do
  1924.         /bin/rmdir "$_rem_dir_dir" 2> /dev/null   # Remove dir if possible
  1925.         if [ $? -ne 0 ]; then                     # Could not remove dir (not an error)
  1926.             return 0
  1927.         fi
  1928.         _rem_dir_dir="`expr \"$_rem_dir_dir\" : '\(.*\)\/.*'`"      # remove rightmost dirname
  1929.     done
  1930.  
  1931.     return 0                                      # Return TRUE
  1932. }
  1933.  
  1934. #------------------------------------------------------------------------------
  1935. # MountPoint - determine the mountpoint of a directory
  1936. #------------------------------------------------------------------------------
  1937. MountPoint()
  1938. {
  1939.     if [ $# -ne 1 ]; then
  1940.         AssertErr "Incorrect arg count in MountPoint()."
  1941.     fi
  1942.  
  1943.     _mnt_pnt_dir_name="$1"
  1944.     #--------------------------------------------------------------------------
  1945.     # Save the name of the dir; strip all spaces in path
  1946.     #--------------------------------------------------------------------------
  1947.     _mnt_pnt_save_name="`echo $_mnt_pnt_dir_name | tr -d  ' ./-'`"
  1948.  
  1949.     #--------------------------------------------------------------------------
  1950.     # Use cached data if it exists
  1951.     #--------------------------------------------------------------------------
  1952.     _mnt_pnt_mount_point="`eval echo \\$_mp_\${_mnt_pnt_save_name}_dir`" 
  1953.  
  1954.     until [ -n "$_mnt_pnt_mount_point" ]; do      # Loop until mountpoint is found
  1955.         IFS='
  1956. '
  1957.         for _mnt_pnt_tmp_line in `$df_cmd $df_arg 2> /dev/null`; do
  1958.             IFS="$S_IFS"
  1959.             set -- "`echo X$_mnt_pnt_tmp_line | awk '{ print($6) }'`"
  1960.             if [ "${1:-NULL}" = "$_mnt_pnt_dir_name" ]; then
  1961.                 _mnt_pnt_mount_point="$_mnt_pnt_dir_name"
  1962.                 continue 2                        # Continue in 'until' loop
  1963.             fi
  1964.         done
  1965.  
  1966.         if [ -z "$_mnt_pnt_mount_point" ]; then            # Haven't found it
  1967.             _mnt_pnt_dir_name="`expr \"$_mnt_pnt_dir_name\" : '\(.*\)\/.*'`"  # remove rightmost dir
  1968.             #------------------------------------------------------------------
  1969.             # The command above will turn '/foo' into '' so we put '/' back
  1970.             #------------------------------------------------------------------
  1971.             if [ -z "$_mnt_pnt_dir_name" ]; then
  1972.                 _mnt_pnt_dir_name='/'                      # If doesn't match now, we're hosed!
  1973.             fi
  1974.         fi
  1975.     done
  1976.  
  1977.     eval _mp_${_mnt_pnt_save_name}_dir=$_mnt_pnt_mount_point 
  1978.  
  1979.     _mnt_pnt_cnt=1
  1980.     while [ $_mnt_pnt_cnt -le $MAX_MNTS ]; do
  1981.         eval _mnt_pnt_mount_point_tmp="\$mnt_point_$_mnt_pnt_cnt"
  1982.         if [ "$_mnt_pnt_mount_point" = "$_mnt_pnt_mount_point_tmp" ]; then
  1983.             return $_mnt_pnt_cnt                           # Return with the mount index
  1984.         else
  1985.             _mnt_pnt_cnt=`expr $_mnt_pnt_cnt + 1` 
  1986.         fi
  1987.     done
  1988.  
  1989.     Alert "$could_not_find_mnt_point_msg"         # Should have returned above
  1990.     return 99                                     # Error detected
  1991. }
  1992.  
  1993. #------------------------------------------------------------------------------
  1994. # SetTopDir - Sets d_dest_dir
  1995. #------------------------------------------------------------------------------
  1996. SetTopDir()
  1997. {
  1998.     if [ "${d_dest_dir:-NULL}" = NULL ]; then
  1999.         AssertErr "d_dest_dir not set in SetTopDir"
  2000.         exit 1
  2001.     fi
  2002.  
  2003.     # If not the default default (or first time) remove the last dir name
  2004.     if [ -z "${master_d_dest_dir}" -a -n "${_ask_inst_pkg_name}" -a "${_ask_inst_pkg_name}" != "E1_MAE" ]; then
  2005.     while [ -z "${master_d_dest_dir}" ]; do
  2006.         if [ -w "${d_dest_dir}" ]; then
  2007.             master_d_dest_dir="${d_dest_dir}"
  2008.         else
  2009.         __tmp_cur_dir=`pwd`
  2010.         cd "$HOME"; __home_dir=`pwd`; cd "$__tmp_cur_dir"
  2011.         master_d_dest_dir="${__home_dir:-/tmp}/apple"
  2012.         fi
  2013.         echo "$where_is_mae_msg"
  2014.         Prompt "    [default=${bld}${master_d_dest_dir}${off}] >>> "
  2015.         read __where_is_mae
  2016.         if [ -n "${__where_is_mae}" ]; then
  2017.         master_d_dest_dir=${__where_is_mae}
  2018.                 if [ ! -r "${master_d_dest_dir}/sys/Finder" -o ! -r "${master_d_dest_dir}/sys/System" -o ! -r "${master_d_dest_dir}/bin/mae" ]; then 
  2019.             echo "    Warning: MAE is not installed there."
  2020.             master_d_dest_dir=''    
  2021.         fi
  2022.         fi
  2023.     done
  2024.     fi
  2025.     if [ "$d_dest_dir" != "${master_d_dest_dir:-$d_dest_dir}" ]; then
  2026.     d_dest_dir="${master_d_dest_dir:-\"$d_dest_dir\"}"
  2027.     fi
  2028.  
  2029.     #--------------------------------------------------------------------------
  2030.     # Get the name of prefered dir
  2031.     #--------------------------------------------------------------------------
  2032.     if [ -n "$default_destination" ]; then        # Set in <package>.STR
  2033.     if [ "$default_destination" != '$d_dest_dir' -a -z "$master_d_dest_dir" ]; then
  2034.         master_d_dest_dir="$d_dest_dir"
  2035.     fi
  2036.         d_dest_dir="${master_d_dest_dir}/${relative_destination}"
  2037.     fi
  2038.  
  2039.     #--------------------------------------------------------------------------
  2040.     # If target dir does not exist create it (remove it before leaving this function)
  2041.     #--------------------------------------------------------------------------
  2042.     if [ ! -d "$d_dest_dir" ]; then
  2043.         MakeDir "$d_dest_dir"                     # Try to create dir
  2044.     fi
  2045.  
  2046.     #--------------------------------------------------------------------------
  2047.     # If d_dest_dir is not accessable then default to HOME directory
  2048.     #--------------------------------------------------------------------------
  2049.     if [ ! -d "$d_dest_dir" -o ! -x "$d_dest_dir" -o ! -w "$d_dest_dir" ]; then
  2050. #        dir="`basename \"$d_dest_dir\"`"          # Get the name of prefered dir
  2051. #        if [ "$dir" != "apple" ]; then
  2052. #            dir="apple/$dir"                      # Add "apple" if not there
  2053. #        fi
  2054.     __tmp_cur_dir=`pwd`
  2055.     cd "$HOME"; __home_dir=`pwd`; cd "$__tmp_cur_dir"
  2056.         set_top_tmp="${__home_dir:-/tmp}/apple"               # Use HOME, or /tmp if not set
  2057. #        d_dest_dir="${set_top_tmp}/$dir"          # Make it a sub dir of HOME
  2058.         d_dest_dir="${set_top_tmp}/${relative_destination}"    # Make it a sub dir of HOME
  2059.     else
  2060.         if [ "${we_made_dir:-FALSE}" = TRUE ]; then
  2061.             cd "$start_dir"                       # In case we're in the dir to be removed
  2062.             /bin/rmdir "$d_dest_dir" 2> /dev/null # Remove dir if empty
  2063.         fi
  2064.     fi
  2065. }
  2066.  
  2067. #------------------------------------------------------------------------------
  2068. # SpaceCheck - calculate free space - needed space; return 1 if insufficient
  2069. #------------------------------------------------------------------------------
  2070. SpaceCheck()
  2071. {
  2072.     if [ $# -ne 2 ]; then
  2073.         AssertErr "Incorrect arg count in SpaceCheck()."
  2074.     fi
  2075.     
  2076.     _spc_chk_dir="$1"                             # Target dir
  2077.  
  2078.     echo "$checking_space_msg"                    # This takes some time - warn them
  2079.  
  2080.     LoadMountList                                 # Get current avail space
  2081.     MountPoint "$_spc_chk_dir"                    # Get mount point for arg
  2082.     mnt_num=$?                                    # Entry into mount_point[]
  2083.     if [ $mnt_num -eq 99 ]; then
  2084.         return 1                                  # Error in MountPoint function
  2085.     fi
  2086.  
  2087.     alloc_space=0
  2088.     _spc_chk_cnt=1
  2089.     while [ $_spc_chk_cnt -le $pkg_cnt ]; do      
  2090.         eval _spc_chk_pkg_name="\$package_$_spc_chk_cnt"
  2091.         eval _spc_chk_inst_var="\$inst_$_spc_chk_pkg_name"   
  2092.         if [ "$_spc_chk_inst_var" != "$yes_msg" ]; then
  2093.             _spc_chk_cnt=`expr $_spc_chk_cnt + 1`
  2094.             continue                              # Not to be installed
  2095.         fi
  2096.         var_dir="`eval echo \\$\${_spc_chk_pkg_name}_dir`"
  2097.     if [ -z "$var_dir" ]; then
  2098.         var_dir="${d_dest_dir}"
  2099.     fi
  2100.         MountPoint "$var_dir"                     # Get mount point for arg dest
  2101.         var_mnt_num=$?                            # Entry into mount_point[]
  2102.         if [ $var_mnt_num -eq 99 ]; then
  2103.             return 1                              # Error in MountPoint function
  2104.         fi
  2105.         if [ $var_mnt_num -ne $mnt_num ]; then
  2106.             _spc_chk_cnt=`expr $_spc_chk_cnt + 1`
  2107.             continue                              # Not on same mount point
  2108.         fi
  2109.         _spc_chk_pkg_size="`eval echo \\$\${_spc_chk_pkg_name}_size`"
  2110.         alloc_space="`expr $alloc_space + $_spc_chk_pkg_size`"
  2111.         _spc_chk_cnt=`expr $_spc_chk_cnt + 1`
  2112.     done
  2113.  
  2114.     eval free_space="\$free_space_$mnt_num"
  2115.     if [ $free_space -lt $alloc_space ]; then
  2116.         Alert "$not_enough_free_space_msg    [ $_spc_chk_dir ]" 
  2117.         return 1
  2118.     else
  2119.         return 0
  2120.     fi
  2121. }
  2122.  
  2123. #------------------------------------------------------------------------------
  2124. # ToLower - Convert input string to lowercase
  2125. #------------------------------------------------------------------------------
  2126. ToLower()
  2127. {
  2128.     if [ $# -ne 1 ]; then AssertErr "ToLower"; fi
  2129.  
  2130.     mixed="`eval echo \\$\$1`"
  2131.  
  2132.     if [ -z "$mixed" ]; then 
  2133.         eval ${1}_lwr=\"\"
  2134.     else
  2135.         #----------------------------------------------------------------------
  2136.         # Convert alphabetic to lowercase and $ to _
  2137.         # Use explicit list to work correctly in certain locales
  2138.         #----------------------------------------------------------------------
  2139.         eval ${1}_lwr=\"`echo $mixed | tr "ABCDEFGHIJKLMNOPQRSTUVWXYZ$" "abcdefghijklmnopqrstuvwxyz_"`\" 
  2140.     fi
  2141. }
  2142.  
  2143. #------------------------------------------------------------------------------
  2144. # TopScreen - clear screen - home cursor - display help banner
  2145. #------------------------------------------------------------------------------
  2146. TopScreen()
  2147. {
  2148.     if Interactive ; then
  2149.         :
  2150.     else
  2151.         return                                    # Don't do anything in batch mode
  2152.     fi
  2153.  
  2154.     if [ $# -eq 0 ]; then
  2155.         banner="$banner_msg"                      # Set default banner
  2156.     else
  2157.         banner="$1"                               # Override default with arg1
  2158.     fi
  2159.  
  2160.     DoClear;                                      # Clear screen - Home cursor
  2161.     echo  "$rev$banner$off"                       # Display banner in rev_video
  2162. }
  2163.  
  2164. #------------------------------------------------------------------------------
  2165. # WaitToContinue - Wait for user to hit RETURN key
  2166. #------------------------------------------------------------------------------
  2167. WaitToContinue()
  2168. {
  2169.     if Interactive ; then
  2170.         :
  2171.     else
  2172.         return                                    # Don't do anything in batch mode
  2173.     fi
  2174.  
  2175.     while :; do
  2176.         Prompt "${hit_ret_side_msg}${bld}${hit_return_msg}${off}"
  2177.         while :; do
  2178.             /bin/stty -echo                       # Don't display input
  2179.             read  key
  2180.             /bin/stty echo                        # Reset to norm
  2181.             case "$key" in
  2182.             '')                   return 0        # Time to move on
  2183.                                   ;;
  2184.             "$help_msg"|\
  2185.             "$help_short_msg")   DoHelp "$no_help_msg"
  2186.                                  return 0
  2187.                                  ;;
  2188.             "$quit_msg"|\
  2189.             "$quit_short_msg")   if [ "$in_quit" = "TRUE" ]; then
  2190.                                      CleanUpExit 0
  2191.                                  fi
  2192.                                  AskQuit "$yes_msg" # Either exit or return here
  2193.                                  continue 2        # Display "Hit RETURN" msg again
  2194.                                  ;;
  2195.             "$q_bang_msg")       CleanUpExit 0
  2196.                                  ;;
  2197.             esac
  2198.         done
  2199.     done
  2200. }
  2201.  
  2202. #------------------------------------------------------------------------------
  2203. # Welcome - Display welcome message and wait to continue
  2204. #------------------------------------------------------------------------------
  2205. Welcome()
  2206. {
  2207.     DoClear
  2208.     echo "$welcome1_msg" 
  2209.     echo "$welcome2_msg" 
  2210.     echo "$welcome3_msg" 
  2211.     WaitToContinue
  2212. }
  2213.  
  2214. #------------------------------------------------------------------------------
  2215. # ShowErrMsg - Display error message, save in report file, and wait to continue
  2216. #------------------------------------------------------------------------------
  2217. ShowErrMsg()
  2218. {
  2219.     TopScreen "$hit_ret_banner_msg";
  2220.     echo
  2221.     /bin/cat "$msg_file"
  2222.     echo
  2223.     Report "`/bin/cat \"$msg_file\"`"    # Save message in report file
  2224.     WaitToContinue
  2225. }
  2226.  
  2227. #------------------------------------------------------------------------------
  2228. # WherePutAll - Ask user where they want to install everything
  2229. #------------------------------------------------------------------------------
  2230. WherePutAll()
  2231. {
  2232.     if [ "$e_pkg_cnt" -lt 1 ]; then               # No Easy packages!
  2233.         AssertErr "No Easy packages in WherePutAll"
  2234.     fi
  2235.  
  2236.     _whr_put_cnt=1
  2237.     _easy_size=0
  2238.     #--------------------------------------------------------------------------
  2239.     # Interested in Easy packages only
  2240.     #--------------------------------------------------------------------------
  2241.     while [ $_whr_put_cnt -le $e_pkg_cnt ]; do
  2242.         eval _whr_put_pkg_name="\$e_package_$_whr_put_cnt"
  2243.         eval inst_$_whr_put_pkg_name="$no_msg"   # Just pretending for a moment
  2244.         _easy_size="`eval expr $_easy_size + \\$\${_whr_put_pkg_name}_size`"
  2245.         _whr_put_cnt=`expr $_whr_put_cnt + 1`
  2246.     done
  2247.  
  2248.     #--------------------------------------------------------------------------
  2249.     # Generate default location based on first package (#1)
  2250.     #--------------------------------------------------------------------------
  2251.     eval _whr_put_pkg_name="\$e_package_1"        # Get name for package number 1
  2252.     eval ${_whr_put_pkg_name}_size=$_easy_size    # Total of all packages
  2253.     eval inst_${_whr_put_pkg_name}="$yes_msg"     # For BadDir call
  2254.     default_destination=''                        # Should be set in *.STR
  2255.     . "$source_dir/LOCALE/$catalog_dir/${_whr_put_pkg_name}.STR"     # Load localized strings file
  2256.     default_destination="${d_dest_dir}/${relative_destination}"
  2257.     Interactive && SetTopDir                      # Sets d_dest_dir (if interactive)
  2258.     eval d_${_whr_put_pkg_name}_dir=\${d_${_whr_put_pkg_name}_dir:-\"$d_dest_dir\"} # Used in AskDir
  2259.  
  2260.     while :; do
  2261.         if Interactive; then
  2262.             #------------------------------------------------------------------
  2263.             # The AskDir function will modify the value of ${_whr_put_pkg_name}_dir. 
  2264.             #------------------------------------------------------------------
  2265.             AskDir "$easy_install_prompt_msg" "$easy_install_help_msg" "$_whr_put_pkg_name" W
  2266.         else
  2267.             #--------------------------------------------------------------
  2268.             # Run validation script
  2269.             #--------------------------------------------------------------
  2270.             "${source_dir}/${_whr_put_pkg_name}.VAL" "`eval echo \\\$d_${_whr_put_pkg_name}_dir`" "$msg_file" destination 2>> "$report_file"
  2271.             if [ $? -ne 0 ]; then                 # Error
  2272.                 if [ -r "$msg_file" -a -s "$msg_file" ]; then
  2273.                     ShowErrMsg
  2274.                 else
  2275.                     Alert "$an_error_msg    (destination)"  # Generic msg
  2276.                 fi
  2277.                 CleanUpExit 0 
  2278.             fi
  2279.             if BadDir "`eval echo \\\$d_${_whr_put_pkg_name}_dir`" "$_whr_put_pkg_name" W; then
  2280.                 CleanUpExit 0 
  2281.             fi
  2282.         fi
  2283.         if [ $? -ne 0 ]; then
  2284.             continue                              # Bad dir - Ask again
  2285.         else
  2286.             break                                 # Good dir - Go on
  2287.         fi
  2288.     done
  2289.  
  2290.     _whr_put_cnt=1
  2291.     d_dest_dir="`eval echo \\$\${_whr_put_pkg_name}_dir`"
  2292.     master_d_dest_dir="${d_dest_dir}" # Set once and save
  2293.     while [ $_whr_put_cnt -le $e_pkg_cnt ]; do
  2294.         eval _whr_put_pkg_name="\$e_package_$_whr_put_cnt"
  2295.         . "$source_dir/LOCALE/$catalog_dir/${_whr_put_pkg_name}.STR"    # Load strings 
  2296.     default_destination="${d_dest_dir}/${relative_destination}"
  2297.         if [ -n "$default_destination" ]; then    # Set in <package>.STR
  2298.             eval ${_whr_put_pkg_name}_dir=\"`echo $default_destination`\"
  2299.         else
  2300.             eval ${_whr_put_pkg_name}_dir="$d_dest_dir" 
  2301.         fi
  2302.         # DEBUG We really should do the full check for each package/destination
  2303.         # but that would take a long time
  2304.         eval inst_$_whr_put_pkg_name="$yes_msg"   # We really do want to install this package
  2305.         _whr_put_cnt=`expr $_whr_put_cnt + 1`     # Increment counter
  2306.     done
  2307.  
  2308.     return 0
  2309. }
  2310.  
  2311. #------------------------------------------------------------------------------
  2312. # WherePutCmdLinePkgs - Ask user where they want to install everything
  2313. #------------------------------------------------------------------------------
  2314. WherePutCmdLinePkgs()
  2315. {
  2316.     if [ "$cmd_line_pkg_cnt" -lt 1 ]; then        # No packages!
  2317.         AssertErr "No cmd_line packages in WherePutCmdLinePkgs"
  2318.     fi
  2319.  
  2320.     #--------------------------------------------------------------------------
  2321.     # Morph the command line packages into Easy packages
  2322.     #--------------------------------------------------------------------------
  2323.     _whr_put_cnt=1
  2324.     e_pkg_cnt=$cmd_line_pkg_cnt                   #Override
  2325.  
  2326.     while [ $_whr_put_cnt -le $e_pkg_cnt ]; do
  2327.         eval _cl_pkg_name=\$cmd_line_pkg_${_whr_put_cnt}
  2328.         eval e_package_${_whr_put_cnt}=$_cl_pkg_name
  2329.         _whr_put_cnt=`expr $_whr_put_cnt + 1`
  2330.     done
  2331.  
  2332.     #--------------------------------------------------------------------------
  2333.     # Check each package against the destination
  2334.     #--------------------------------------------------------------------------
  2335.     _whr_put_cnt=1
  2336. #    if [ -z "$cmd_line_dest" ]; then
  2337. #    if [ -w '/' ]; then
  2338. #        cmd_line_dest="/opt/apple"
  2339. #    else
  2340. #        cmd_line_dest="${HOME:-/tmp}/apple"
  2341. #    fi
  2342. #    fi
  2343.     if [ ! -d "$d_dest_dir" ]; then
  2344.         MakeDir "$d_dest_dir"                     # Try to create dir
  2345.     fi
  2346.     if [ ! -d "$d_dest_dir" -o ! -x "$d_dest_dir" -o ! -w "$d_dest_dir" ]; then
  2347.     __tmp_cur_dir=`pwd`
  2348.     cd "$HOME"; __home_dir=`pwd`; cd "$__tmp_cur_dir"
  2349.         d_dest_dir="${__home_dir:-/tmp}/apple"    # Use HOME, or /tmp if not set
  2350.     fi
  2351.     while [ "$_whr_put_cnt" -le "$e_pkg_cnt" ]; do
  2352.         default_destination=''                        # Should be set in *.STR
  2353. #        d_dest_dir="$cmd_line_dest"
  2354.         eval _whr_put_pkg_name="\$e_package_${_whr_put_cnt}"
  2355.  
  2356.         . "$source_dir/LOCALE/$catalog_dir/${_whr_put_pkg_name}.STR"  # Set default_destination
  2357.     default_destination="${d_dest_dir}/${relative_destination}"
  2358.     eval ${_whr_put_pkg_name}_dir=\"`echo $default_destination`\"
  2359.  
  2360. #        if [ -n "$default_destination" ]; then    # Set in <package>.STR
  2361. #            eval ${_whr_put_pkg_name}_dir=\"`echo $default_destination`\"
  2362. #        else
  2363. #        eval ${_whr_put_pkg_name}_dir="$d_dest_dir" 
  2364. #        fi
  2365.  
  2366.         _dest_dir="`eval echo $default_destination`"
  2367.  
  2368.     "${source_dir}/${_whr_put_pkg_name}.VAL" '' /dev/null ask_dest >/dev/null 2>&1
  2369.     ask_dest=$?
  2370.  
  2371.     if [ "$ask_dest" -eq 0 -a -z "$cmd_line_dest" ]; then
  2372.         #-------------------------------------------------------------
  2373.         # Somehow we don't have a destination (probably no -d on the 
  2374.         # command line)
  2375.         #-------------------------------------------------------------
  2376.         while :; do
  2377.         eval d_${_whr_put_pkg_name}_dir=\"$_dest_dir\"
  2378.         #----------------------------------------------------------
  2379.         # Gets directory and validates
  2380.         #----------------------------------------------------------
  2381.         AskDir "$destination_prompt_msg" "$destination_help_msg" "$_whr_put_pkg_name" W
  2382.         if [ $? -ne 0 ]; then
  2383.             continue
  2384.         else
  2385.             break
  2386.         fi
  2387.         done
  2388.         if [ "${_whr_put_pkg_name}" = "E1_MAE" ]; then
  2389.         master_d_dest_dir="${_whr_put_pkg_name}"
  2390.         elif [ -z "$master_d_dest_dir" ]; then
  2391.         # ask where is mae
  2392.         while [ -z "$master_d_dest_dir" ]; do
  2393.             if [ -w "${d_dest_dir}" ]; then
  2394.             master_d_dest_dir="${d_dest_dir}"
  2395.             else
  2396.             __tmp_cur_dir=`pwd`
  2397.             cd "$HOME"; __home_dir=`pwd`; cd "$__tmp_cur_dir"
  2398.             master_d_dest_dir="${__home_dir:-/tmp}/apple"
  2399.             fi
  2400.             echo "$where_is_mae_msg"
  2401.             Prompt "    [default=${bld}${master_d_dest_dir}${off}] >>> "
  2402.             read __where_is_mae
  2403.             if [ -n "${__where_is_mae}" ]; then
  2404.             master_d_dest_dir=${__where_is_mae}
  2405.             if [ ! -r "${master_d_dest_dir}/sys/Finder" -o ! -r "${master_d_dest_dir}/sys/System" -o ! -r "${master_d_dest_dir}/bin/mae" ]; then 
  2406.                 echo "    Warning: MAE is not installed there."
  2407.                 master_d_dest_dir=''    
  2408.             fi
  2409.             fi
  2410.         done
  2411.         fi
  2412.     else
  2413.         eval d_${_whr_put_pkg_name}_dir=\"$_dest_dir\"
  2414.  
  2415.         #--------------------------------------------------------------
  2416.         # Run validation script
  2417.         #--------------------------------------------------------------
  2418.         ## "${source_dir}/${_whr_put_pkg_name}.VAL" "`eval echo \\\$d_${_whr_put_pkg_name}_dir`" "$msg_file" destination 2>> "$report_file"
  2419.  
  2420.         "${source_dir}/${_whr_put_pkg_name}.VAL" "$default_destination" "$msg_file" destination 2>> "$report_file"
  2421.         if [ $? -ne 0 ]; then                 # Error
  2422.         if [ -r "$msg_file" -a -s "$msg_file" ]; then
  2423.             ShowErrMsg
  2424.         else
  2425.             Alert "$an_error_msg    (destination)"  # Generic msg
  2426.         fi
  2427.         CleanUpExit 0 
  2428.         fi
  2429.         #-------------------------------------------------------------------
  2430.         # Now make sure the receiving directory is OK
  2431.         #-------------------------------------------------------------------
  2432.         if BadDir "`eval echo \\\$d_${_whr_put_pkg_name}_dir`" "$_whr_put_pkg_name" W; then
  2433.         CleanUpExit 0 
  2434.         fi
  2435.     fi
  2436.         # let _whr_put_cnt=$_whr_put_cnt+1
  2437.         _whr_put_cnt=`expr $_whr_put_cnt + 1`
  2438.     done
  2439.     if [ "$quiet" = TRUE ]; then
  2440.     interactive=FALSE
  2441.     fi
  2442.  
  2443.     return 0
  2444. }
  2445.  
  2446. ###############################################################################
  2447. ## Main - Main program begins                                                ##
  2448. ###############################################################################
  2449.  
  2450. #------------------------------------------------------------------------------
  2451. # Identify OS   - sets o_s (or exits)
  2452. #------------------------------------------------------------------------------
  2453. GetOS
  2454.  
  2455. #------------------------------------------------------------------------------
  2456. # Initialize platform specific vars - sets lots of things
  2457. #------------------------------------------------------------------------------
  2458. InitVars
  2459.  
  2460. #------------------------------------------------------------------------------
  2461. # Locate source files (or exit) - sets source_dir
  2462. #------------------------------------------------------------------------------
  2463. FindSourceDir
  2464.  
  2465. #------------------------------------------------------------------------------
  2466. # Get command line options - sets interactive, inst_mode, d_dest_dir
  2467. #------------------------------------------------------------------------------
  2468. GetOpts
  2469.  
  2470. #------------------------------------------------------------------------------
  2471. # Start the report log file with the date, command args, and O/S version
  2472. #------------------------------------------------------------------------------
  2473. echo "`date`"               >  "$report_file"     # Create the file
  2474. echo "$0 $argv"             >> "$report_file"
  2475. echo "`/bin/uname -sr`"     >> "$report_file"
  2476. echo '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -' >> "$report_file"
  2477.  
  2478. #------------------------------------------------------------------------------
  2479. # Based on the current settings, jump into the main loop at the apropriate state
  2480. #------------------------------------------------------------------------------
  2481. case $inst_mode in
  2482.     '')        state=Welcome                      # Normal default
  2483.                ;;
  2484.     EASY)      state=WherePutAll                  # Quick Easy
  2485.                ;;
  2486.     CUSTOM)    if [ "$cmd_line_pkg_cnt" -gt 0 ]; then
  2487.                    state=WherePutCmdLinePkgs      # Command Line Choices
  2488.                else
  2489.                    state=AskInstPkgs              # Quick Custom
  2490.                fi
  2491.                ;;
  2492.     REMOVE)    if [ "$cmd_line_pkg_cnt" -gt 0 ]; then
  2493.                    state=RemCmdLinePkgs           # Command Line Choices
  2494.                else
  2495.                    state=AskRemPkgs               # Quick Remove
  2496.                fi
  2497.                ;;
  2498.     *)         AssertErr "Invalid state entering main loop"
  2499.                ;;
  2500. esac
  2501.  
  2502. #-------------------------------------------------------------------------------
  2503. # Main loop controls flow of execution
  2504. #-------------------------------------------------------------------------------
  2505. while :; do
  2506.     case "$state" in 
  2507.     Welcome)       Welcome                        # Display welcome message
  2508.                    state=FindPackages
  2509.                    ;;
  2510.     FindPackages)  FindPackages                   # Sets pkg_cnt/e_pkg_cnt/r_pkg_cnt (or exit)
  2511.                    state=ListPackages
  2512.                    ;;
  2513.     ListPackages)  ListPackages                   # Display package info 
  2514.                    state=AskInstMode
  2515.                    ;;
  2516.     AskInstMode)   AskInstMode                    # Modifies inst_mode
  2517.                    case $inst_mode in
  2518.                        EASY)    state=WherePutAll ;;
  2519.                        CUSTOM)  state=AskInstPkgs ;;
  2520.                        REMOVE)  state=AskRemPkgs ;;
  2521.                        *)       AssertErr "Invalid inst_mode in main loop." ;;
  2522.                    esac
  2523.                    ;;
  2524.     AskInstPkgs)   AskInstPkgs                    # Modifies inst_*
  2525.                    state=Confirm
  2526.                    ;;
  2527.     AskRemPkgs)    AskRemPkgs                     # Modifies rem_*
  2528.                    state=Confirm
  2529.                    ;;
  2530.     RemCmdLinePkgs)    RemCmdLinePkgs             # 
  2531.                    state=Confirm
  2532.                    ;;
  2533.     WherePutAll)   WherePutAll                    # 
  2534.                    state=Confirm
  2535.                    ;;
  2536.     WherePutCmdLinePkgs)   WherePutCmdLinePkgs    # 
  2537.                    state=Confirm
  2538.                    ;;
  2539.     Confirm)       if Confirm; then               
  2540.                        if [ $inst_mode = REMOVE ]; then
  2541.                            state=DoRemove         # Go Forward to Remove
  2542.                        else
  2543.                            state=DoInstall        # Go forward to Install
  2544.                        fi
  2545.                    else
  2546.                        if [ "$cmd_line_pkg_cnt" -gt 0 ]; then
  2547.                            _no_operation=TRUE
  2548.                            state=Epilogue
  2549.                        else
  2550.                            state=AskInstMode          # Go Back 
  2551.                        fi
  2552.                    fi
  2553.                    if [ "$cmd_line_pkg_cnt" -gt 0 ]; then
  2554.                        interactive=FALSE
  2555.                    fi
  2556.                    ;;
  2557.     DoInstall)     DoInstall                      # Does not return
  2558.                    state=Epilogue
  2559.                    ;;
  2560.     DoRemove)      DoRemove                       # Does not return
  2561.                    state=Epilogue
  2562.                    ;;
  2563.     Epilogue)      Epilogue
  2564.                    ;;
  2565.     *)             AssertErr "Invalid State! State = '$state'."
  2566.                    ;;
  2567.     esac
  2568. done
  2569.  
  2570.